home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / os2 / xdsn217.zip / DOC / isolib.inf (.txt) < prev    next >
OS/2 Help File  |  1996-07-07  |  179KB  |  6,036 lines

  1.  
  2. ΓòÉΓòÉΓòÉ 1. Disclaimer ΓòÉΓòÉΓòÉ
  3.  
  4. This on-line document was generated automatically from its printed version 
  5. LaTeX source. Some places in the document (especially tables) may look ugly due 
  6. to the conversion program limits. These problems are being worked on and are 
  7. supposed to be solved in the final release. 
  8.  
  9.  
  10. ΓòÉΓòÉΓòÉ 2. Title Page ΓòÉΓòÉΓòÉ
  11.  
  12.  xTech Development System 
  13.  
  14.  ISO Modula-2 Library Reference 
  15.  
  16.  xTech Ltd, 1996 
  17.  
  18. XDS software and documentation copyright (c) 1991-1996 xTech Ltd. (xTech). 
  19.  
  20. Information in this document is subject to change without notice and does not 
  21. represent a commitment on the part of xTech. 
  22.  
  23. All rights reserved. You may use the enclosed software on a single computer; 
  24. transfer the software from one computer to another, provided that the software 
  25. is used on only one computer at a time and that you remove any copies of the 
  26. software on the computer from which the copies were made; make copies of the 
  27. software for backup purposes only. 
  28.  
  29. XDS software and documentation have been tested and reviewed. Nevertheless, 
  30. xTech makes no warranty or representation, either express or implied, with 
  31. respect to the software and documentation included with XDS. In no event will 
  32. xTech be liable for direct, indirect, special, incidental or consequential 
  33. damages resulting from any defect in the software or documentation included 
  34. with this product. In particular, xTech shall have no liability for any 
  35. programs or data used with this product, including the cost of recovering 
  36. programs or data. 
  37.  
  38. XDS is a trademark of xTech Ltd. 
  39.  
  40. All trademarks and copyrights mentioned in this documentation are the property 
  41. of their respective holders. 
  42.  
  43.  
  44. ΓòÉΓòÉΓòÉ 3. Input/Output ΓòÉΓòÉΓòÉ
  45.  
  46. The input/output library defined in this chapter provides facilities for 
  47. reading and writing of data streams over one or more channels. Channels are 
  48. connected to sources of input data, or to destinations of output data, known as 
  49. devices or device instances. There is a separation between modules that are 
  50. concerned with device-independent operations, such as reading and writing, and 
  51. modules concerned with device-dependent operations, such as making connections 
  52. to named files. This separation allows the library to be extended to work with 
  53. new devices. The module structure of the library is depicted in the following 
  54. figure. 
  55.  
  56. The figure will be available in the final release 
  57.  
  58. Channels already open to standard sources and destinations can be identified 
  59. using procedures provided by the module StdChans. This module also provides for 
  60. the identification and selection of channels used by default for input and 
  61. output operations. 
  62.  
  63. The modules TextIO, WholeIO, RealIO, and LongIO, provide facilities that allow 
  64. the reading and writing of high-level units of data, using text operations on 
  65. channels specified explicitly by a parameter. These high-level units include 
  66. characters, strings, and whole numbers and real numbers in decimal notation. 
  67. The module RawIO provides facilities for reading and writing of arbitrary data 
  68. types, using raw (binary) operations on explicitly specified channels. 
  69.  
  70. Text operations produce or consume data streams as sequences of characters and 
  71. line marks. Raw operations produce or consume data streams as sequences of 
  72. storage locations (i.e. as arrays whose component type is SYSTEM.LOC). 
  73.  
  74. The library allows devices to support both text and raw operations on a single 
  75. channel, although this behaviour is not required. 
  76.  
  77. The module IOResult provides the facility for a program to determine whether 
  78. the last operation to read data from a specified input channel found data in 
  79. the required format. 
  80.  
  81. Corresponding to the TextIO group of modules is a group of modules STextIO, 
  82. SWholeIO, SRealIO, SLongIO, SRawIO and SIOResult. The prefix "S" serves as an 
  83. abbreviation for "Simple". The procedures exported from this group do not take 
  84. parameters identifying a channel. They operate on the default input and output 
  85. channels, as identified by the module StdChans. 
  86.  
  87. The module IOConsts defines types and constants used by IOResult and SIOResult. 
  88.  
  89. The device modules StreamFile, SeqFile, RndFile, and TermFile provide 
  90. facilities that allow a channel to be opened to a named stream, to a rewindable 
  91. sequential file, to a random access file, or to a terminal device respectively. 
  92. The device module ProgramArgs provides an open channel from which program 
  93. arguments may be read. Device specific operations, such as positioning within a 
  94. random access file, are also defined by the appropriate device module. 
  95.  
  96. The module ChanConsts defines the constants and types used in those device 
  97. module procedures that open channels. 
  98.  
  99. The primitive device-independent operations on channels are provided by the 
  100. module IOChan. 
  101.  
  102. The module IOChan defines general input/output library exception values that 
  103. may be raised when using any device through a channel. Device errors, such as a 
  104. hardware read/write error, are reported by raising one of the general exception 
  105. values, and providing an implementation-defined error number. Exception values 
  106. associated with device- specific operations are defined by the appropriate 
  107. device module. 
  108.  
  109. The module IOLink provides facilities that allow a user to provide further 
  110. specialized device modules for use with channels, following the pattern of the 
  111. rest of the library. 
  112.  
  113. NOTE: 
  114.  
  115. Partial implementations of the input/output library may provide modules 
  116. selected exclusively from the group STextIO, SWholeIO, SRealIO, and SLongIO, 
  117. normally with SIOResult and IOConsts. If any other module is provided, the 
  118. module IOChan must also be provided, in accordance with the import dependencies 
  119. between the definition modules of the library. 
  120.  
  121.      Standard and Default Channels 
  122.      Reading and Writing of Data 
  123.      Device-Independent Channel Operations 
  124.      Obtaining Channels from Device Modules 
  125.      Interface to Channels for New Device Modules 
  126.  
  127.  
  128. ΓòÉΓòÉΓòÉ 3.1. Standard and Default Channels ΓòÉΓòÉΓòÉ
  129.  
  130. Standard channels do not have to be opened by a client program since they are 
  131. already open and ready for use. Under some operating systems they may be 
  132. connected to sources and destinations specified before the program is run, 
  133. while on a stand-alone system they may be connected to a console terminal. 
  134.  
  135. No method is provided for closing a standard channel, and the values used to 
  136. identify standard channels are constant throughout the execution of the 
  137. program. 
  138.  
  139. Default channels are channels whose identities have been stored as those to be 
  140. used by default for input and output operations. Initially these correspond to 
  141. the standard channels, but their values may be varied to obtain the effect of 
  142. redirection. 
  143.  
  144.      Module StdChans 
  145.  
  146.  
  147. ΓòÉΓòÉΓòÉ 3.1.1. Module StdChans ΓòÉΓòÉΓòÉ
  148.  
  149. The module StdChans defines functions that identify channels already open to 
  150. implementation-defined sources and destinations of standard input, standard 
  151. output, and standard error output. Access to a `null device' is provided to 
  152. allow unwanted output to be suppressed. The null device throws away all data 
  153. written to it, and gives an immediate end of input indication on reading. 
  154.  
  155. The module StdChans provides procedures for identification and selection of the 
  156. channels used by default for input and output operations. 
  157.  
  158.      ChanID - Channel identity 
  159.      StdInChan - Get standard input channel id 
  160.      StdOutChan - Get standard output channel id 
  161.      StdErrChan - Get standard error channel id 
  162.      NullChan - Get null device channel id 
  163.      InChan - Get current default input channel id 
  164.      OutChan - Get current default output channel id 
  165.      ErrChan - Get current default error channel id 
  166.      SetInChan - Set current default input channel 
  167.      SetOutChan - Set current default output channel 
  168.      SetErrChan - Set current default output channel 
  169.  
  170.  
  171. ΓòÉΓòÉΓòÉ 3.1.1.1. ChanID - Channel identity ΓòÉΓòÉΓòÉ
  172.  
  173. TYPE
  174.   ChanId = IOChan.ChanId;
  175.  
  176. Module StdChans 
  177.  
  178. The type IOChan.ChanId which it used to identify channels is reexported. 
  179.  
  180.  
  181. ΓòÉΓòÉΓòÉ 3.1.1.2. StdInChan - Get standard input channel id ΓòÉΓòÉΓòÉ
  182.  
  183. PROCEDURE StdInChan (): ChanId;
  184.  
  185. Module StdChans 
  186.  
  187. The function procedure StdInChan returns a value identifying a channel open to 
  188. the implementation-defined standard source for program input. 
  189.  
  190.  
  191. ΓòÉΓòÉΓòÉ 3.1.1.3. StdOutChan - Get standard output channel id ΓòÉΓòÉΓòÉ
  192.  
  193. PROCEDURE StdOutChan (): ChanId;
  194.  
  195. Module StdChans 
  196.  
  197. The function procedure StdOutChan returns a value identifying a channel open to 
  198. the implementation-defined standard destination for program output. 
  199.  
  200.  
  201. ΓòÉΓòÉΓòÉ 3.1.1.4. StdErrChan - Get standard error channel id ΓòÉΓòÉΓòÉ
  202.  
  203. PROCEDURE StdErrChan (): ChanId;
  204.  
  205. Module StdChans 
  206.  
  207. The function procedure StdErrChan returns a value identifying a channel open to 
  208. the implementation-defined standard destination for program error messages. 
  209.  
  210.  
  211. ΓòÉΓòÉΓòÉ 3.1.1.5. NullChan - Get null device channel id ΓòÉΓòÉΓòÉ
  212.  
  213. PROCEDURE NullChan (): ChanId;
  214.  
  215. Module StdChans 
  216.  
  217. The function procedure NullChan returns a value identifying a channel open to 
  218. the null device. 
  219.  
  220. NOTE: 
  221.  
  222. The null device supports all operations by discarding all data written to it, 
  223. or by giving an immediate end of input indication on reading. 
  224.  
  225.  
  226. ΓòÉΓòÉΓòÉ 3.1.1.6. InChan - Get current default input channel id ΓòÉΓòÉΓòÉ
  227.  
  228. PROCEDURE InChan (): ChanId;
  229.  
  230. Module StdChans 
  231.  
  232. The function procedure InChan returns the identity of the current default input 
  233. channel. This is the channel used by input procedures that do not take a 
  234. channel parameter. Initially this is the value returned by StdInChan. 
  235.  
  236.  
  237. ΓòÉΓòÉΓòÉ 3.1.1.7. OutChan - Get current default output channel id ΓòÉΓòÉΓòÉ
  238.  
  239. PROCEDURE OutChan (): ChanId;
  240.  
  241. Module StdChans 
  242.  
  243. The function procedure OutChan returns the identity of the current default 
  244. output channel. This is the channel used by output procedures that do not take 
  245. a channel parameter. Initially this is the value returned by StdOutChan. 
  246.  
  247.  
  248. ΓòÉΓòÉΓòÉ 3.1.1.8. ErrChan - Get current default error channel id ΓòÉΓòÉΓòÉ
  249.  
  250. PROCEDURE ErrChan (): ChanId;
  251.  
  252. Module StdChans 
  253.  
  254. The function procedure ErrChan returns the identity of the current default 
  255. output channel for program error messages. Initially this is the value returned 
  256. by StdErrChan. 
  257.  
  258.  
  259. ΓòÉΓòÉΓòÉ 3.1.1.9. SetInChan - Set current default input channel ΓòÉΓòÉΓòÉ
  260.  
  261. PROCEDURE SetInChan (cid: ChanId);
  262.  
  263. Module StdChans 
  264.  
  265. The procedure SetInChan sets the current default input channel to that 
  266. identified by cid. 
  267.  
  268.  
  269. ΓòÉΓòÉΓòÉ 3.1.1.10. SetOutChan - Set current default output channel ΓòÉΓòÉΓòÉ
  270.  
  271. PROCEDURE SetOutChan (cid: ChanId);
  272.  
  273. Module StdChans 
  274.  
  275. The procedure SetOutChan sets the current default output channel to that 
  276. identified by cid. 
  277.  
  278.  
  279. ΓòÉΓòÉΓòÉ 3.1.1.11. SetErrChan - Set current default output channel ΓòÉΓòÉΓòÉ
  280.  
  281. PROCEDURE SetErrChan (cid: ChanId);
  282.  
  283. Module StdChans 
  284.  
  285. The procedure SetErrChan sets the current default output channel for error 
  286. messages to that identified by cid. 
  287.  
  288.  
  289. ΓòÉΓòÉΓòÉ 3.2. Reading and Writing of Data ΓòÉΓòÉΓòÉ
  290.  
  291. The module TextIO provides facilities for input and output of characters, 
  292. character strings, and line marks, using text operations. 
  293.  
  294. The module WholeIO provides facilities for input and output of whole numbers in 
  295. decimal text form. 
  296.  
  297. The modules RealIO and LongIO provide facilities for input and output of real 
  298. numbers in decimal text form. 
  299.  
  300. The module RawIO provides facilities for direct input and output of data, using 
  301. raw operations (i.e. without any interpretation). 
  302.  
  303. The input procedures of the modules TextIO, WholeIO, RealIO, LongIO, and RawIO 
  304. are sufficient for use where the format of the input data is known. Since, in 
  305. practice, their use may be inconsistent with the format of the input data, they 
  306. have the effect of setting a `read result' for the used channel. The module 
  307. IOResult provides the facility for obtaining the read result applicable to the 
  308. most recent input operation on a given channel. 
  309.  
  310. In all cases, channels are selected explicitly by passing an actual parameter 
  311. of the type ChanId to the procedures of these modules. 
  312.  
  313. The modules STextIO, SWholeIO, SRealIO, SLongIO, SRawIO, and SIOResult provide 
  314. the set of similar procedures set that operate over default input and output 
  315. channels, and so do not take a parameter identifying a channel. 
  316.  
  317.      Modules TextIO and STextIO 
  318.      Modules WholeIO and SWholeIO 
  319.      Modules RealIO, SRealIO, LongIO, and SLongIO 
  320.      Modules RawIO and SRawIO 
  321.      Module IOConsts 
  322.      Modules IOResult and SIOResult 
  323.  
  324.  
  325. ΓòÉΓòÉΓòÉ 3.2.1. Modules TextIO and STextIO ΓòÉΓòÉΓòÉ
  326.  
  327. The module TextIO provides facilities for input and output of characters, 
  328. character strings, and line marks, using text operations. 
  329.  
  330. The procedures of the module STextIO behave as the corresponding procedures of 
  331. the module TextIO, except that input is taken from the default input channel, 
  332. and output is sent to the default output channel. 
  333.  
  334.      ReadChar - Read a character 
  335.      ReadRestLine - Read rest of line 
  336.      ReadString - Read a string 
  337.      ReadToken - Read a space-delimited token 
  338.      SkipLine - Skip rest of input line 
  339.      WriteChar - Write a character 
  340.      WriteLn - Write a line mark 
  341.      WriteString - Write a string 
  342.  
  343.  
  344. ΓòÉΓòÉΓòÉ 3.2.1.1. ReadChar - Read a character ΓòÉΓòÉΓòÉ
  345.  
  346. PROCEDURE ReadChar (cid: IOChan.ChanId; VAR ch: CHAR);
  347. PROCEDURE ReadChar (VAR ch: CHAR);
  348.  
  349. Modules: TextIO, STextIO 
  350.  
  351. If there is a character next in the input stream identified by cid, the 
  352. procedure ReadChar removes it from the stream and assigns its value to ch; 
  353. otherwise the value of ch is not defined. The read result for the channel is 
  354. set to the value 
  355.  
  356.  allRight  if a character is read; 
  357.  
  358.  endOfLine if no character is read, the next item being a line mark; 
  359.  
  360.  endOfInput if no character is read, the input stream having ended. 
  361.  
  362.  
  363. ΓòÉΓòÉΓòÉ 3.2.1.2. ReadRestLine - Read rest of line ΓòÉΓòÉΓòÉ
  364.  
  365. PROCEDURE ReadRestLine (cid: IOChan.ChanId;
  366.                         VAR s: ARRAY OF CHAR);
  367. PROCEDURE ReadRestLine (VAR s: ARRAY OF CHAR);
  368.  
  369. Modules: TextIO, STextIO 
  370.  
  371. If there is a character next in the input stream identified by cid, the 
  372. procedure ReadRestLine reads a string of characters; reading continues as long 
  373. as there are still characters before the next line mark or the end of the 
  374. stream. As much of the string as can be accommodated is copied to s as a string 
  375. value. The read result for the channel is set to the value 
  376.  
  377.  allRight  if s is not empty and accomodates all of the string that has been 
  378.            read; 
  379.  
  380.  outOfRange if s is not empty but does not accommodate all of the string; 
  381.  
  382.  endOfLine if s is empty, the next item being a line mark; 
  383.  
  384.  endOfInput if s is empty, the input stream having ended. 
  385.  
  386.  
  387. ΓòÉΓòÉΓòÉ 3.2.1.3. ReadString - Read a string ΓòÉΓòÉΓòÉ
  388.  
  389. PROCEDURE ReadString (cid: IOChan.ChanId;
  390.                       VAR s: ARRAY OF CHAR);
  391. PROCEDURE ReadString (VAR s: ARRAY OF CHAR);
  392.  
  393. Modules: TextIO, STextIO 
  394.  
  395. If there is a character next in the input stream identified by cid, the 
  396. procedure ReadString reads a string of characters; reading continues as long as 
  397. there are still characters before the next line mark or the end of the stream 
  398. and the capacity of s has not been exhausted. The string is copied to s as a 
  399. string value. The read result for the channel is set to the value 
  400.  
  401.  allRight  if s is not empty; 
  402.  
  403.  endOfLine if s is empty, the next item being a line mark; 
  404.  
  405.  endOfInput if s is empty, the input stream having ended. 
  406.  
  407.  
  408. ΓòÉΓòÉΓòÉ 3.2.1.4. ReadToken - Read a space-delimited token ΓòÉΓòÉΓòÉ
  409.  
  410. PROCEDURE ReadToken (cid: IOChan.ChanId;
  411.                      VAR s: ARRAY OF CHAR);
  412. PROCEDURE ReadToken (VAR s: ARRAY OF CHAR);
  413.  
  414. Modules: TextIO, STextIO 
  415.  
  416. The procedure ReadToken first skips any leading spaces in the input stream 
  417. identified by cid. If the next item is a character, a string of characters is 
  418. read; reading continues as long as there are still non-space characters before 
  419. the next line mark or the end of the stream. As much of the string as can be 
  420. accommodated is copied to s as a string value. The read result for the channel 
  421. is set to the value 
  422.  
  423.  allRight  if s is not empty and accomodates all of the string that has been 
  424.            read; 
  425.  
  426.  outOfRange if s is not empty but does not accommodate all of the string; 
  427.  
  428.  endOfLine if s is empty, the next item being a line mark; 
  429.  
  430.  endOfInput if s is empty, the input stream having ended. 
  431.  
  432.  
  433. ΓòÉΓòÉΓòÉ 3.2.1.5. SkipLine - Skip rest of input line ΓòÉΓòÉΓòÉ
  434.  
  435. PROCEDURE SkipLine (cid: IOChan.ChanId);
  436. PROCEDURE SkipLine ();
  437.  
  438. Modules: TextIO, STextIO 
  439.  
  440. The procedure SkipLine reads successive items from the input stream identified 
  441. by cid up to and including the next line mark, or until the end of the stream 
  442. is reached. 
  443.  
  444. The read result for the channel is set to the value 
  445.  
  446.  allRight  if a line mark is read; 
  447.  
  448.  endOfInput if no line mark is read, the input stream having ended. 
  449.  
  450.  
  451. ΓòÉΓòÉΓòÉ 3.2.1.6. WriteChar - Write a character ΓòÉΓòÉΓòÉ
  452.  
  453. PROCEDURE WriteChar (cid: IOChan.ChanId; ch: CHAR);
  454. PROCEDURE WriteChar (ch: CHAR);
  455.  
  456. The procedure WriteChar writes the character ch to the output stream identified 
  457. by cid. 
  458.  
  459.  
  460. ΓòÉΓòÉΓòÉ 3.2.1.7. WriteLn - Write a line mark ΓòÉΓòÉΓòÉ
  461.  
  462. PROCEDURE WriteLn (cid: IOChan.ChanId);
  463. PROCEDURE WriteLn ();
  464.  
  465. Modules: TextIO, STextIO 
  466.  
  467. The procedure WriteLn writes a line mark to the output stream identified by 
  468. cid. 
  469.  
  470.  
  471. ΓòÉΓòÉΓòÉ 3.2.1.8. WriteString - Write a string ΓòÉΓòÉΓòÉ
  472.  
  473. PROCEDURE WriteString (cid: IOChan.ChanId;
  474.                        s: ARRAY OF CHAR);
  475. PROCEDURE WriteString (s: ARRAY OF CHAR);
  476.  
  477. Modules: TextIO, STextIO 
  478.  
  479. The procedure WriteString writes the string value in s to the output stream 
  480. identified by cid. 
  481.  
  482.  
  483. ΓòÉΓòÉΓòÉ 3.2.2. Modules WholeIO and SWholeIO ΓòÉΓòÉΓòÉ
  484.  
  485. The module WholeIO provides facilities for input and output of whole numbers in 
  486. decimal text form. 
  487.  
  488. The text form of a signed whole number is 
  489.  
  490. ["+" | "-"], decimal digit, {decimal digit}
  491.  
  492. The text form of an unsigned whole number is 
  493.  
  494. decimal digit, {decimal digit}
  495.  
  496. The procedures of the module SWholeIO behave as the corresponding procedures of 
  497. the module WholeIO, except that input is taken from the default input channel, 
  498. and output is sent to the default output channel. 
  499.  
  500.      ReadInt - Read an INTEGER value 
  501.      WriteInt - Write an INTEGER value 
  502.      ReadCard - Read a CARDINAL value 
  503.      WriteCard - Write a CARDINAL value 
  504.  
  505.  
  506. ΓòÉΓòÉΓòÉ 3.2.2.1. ReadInt - Read an INTEGER value ΓòÉΓòÉΓòÉ
  507.  
  508. PROCEDURE ReadInt (cid: IOChan.ChanId;
  509.                    VAR int: INTEGER);
  510. PROCEDURE ReadInt (VAR int: INTEGER);
  511.  
  512. Modules: WholeIO, SWholeIO 
  513.  
  514. The procedure ReadInt skips any leading spaces from the input stream identified 
  515. by cid, and then reads characters that form a signed whole number. The read 
  516. result for the channel is set to the value 
  517.  
  518.  allRight  if a signed whole number is read, and its value is in the range of 
  519.            the type INTEGER; the value of this number is assigned to int; 
  520.  
  521.  outOfRange if a signed whole number is read, but its value is out of range of 
  522.            the type INTEGER; the value MAX(INTEGER) or MIN(INTEGER) is assigned 
  523.            to int according to the sign of the number; 
  524.  
  525.  wrongFormat if there are characters read or to be read, but these are not in 
  526.            the format of a signed whole number; the value of int is not 
  527.            defined; 
  528.  
  529.  endOfLine if no characters are read, the next item being a line mark; the 
  530.            value of int is not defined; 
  531.  
  532.  endOfInput if no characters are read, the input having ended; the value of int 
  533.            is not defined. 
  534.  
  535.  
  536. ΓòÉΓòÉΓòÉ 3.2.2.2. WriteInt - Write an INTEGER value ΓòÉΓòÉΓòÉ
  537.  
  538. PROCEDURE WriteInt (cid: IOChan.ChanId;
  539.                     int: INTEGER;
  540.                     width: CARDINAL);
  541. PROCEDURE WriteInt (int: INTEGER;
  542.                     width: CARDINAL);
  543.  
  544. Modules: WholeIO, SWholeIO 
  545.  
  546. The procedure WriteInt writes the value of int to the output stream identified 
  547. by cid in text form, with leading spaces as required to make the number of 
  548. characters written at least that given by width. A sign is written only for 
  549. negative values. In the special case of a value of zero for width, exactly one 
  550. leading space is written. 
  551.  
  552.  
  553. ΓòÉΓòÉΓòÉ 3.2.2.3. ReadCard - Read a CARDINAL value ΓòÉΓòÉΓòÉ
  554.  
  555. PROCEDURE ReadCard (cid: IOChan.ChanId;
  556.                     VAR card: CARDINAL);
  557. PROCEDURE ReadCard (VAR card: CARDINAL);
  558.  
  559. Modules: WholeIO, SWholeIO 
  560.  
  561. The procedure ReadCard skips any leading spaces from the input stream 
  562. identified by cid, and then reads characters that form an unsigned whole 
  563. number. The read result for the channel is set to the value 
  564.  
  565.  allRight  if an unsigned whole number is read, and its value is in the range 
  566.            of the type CARDINAL; the value of the number is assigned to card; 
  567.  
  568.  outOfRange if a signed whole number is read, but its value is out of range of 
  569.            the values of the type CARDINAL; the value MAX(CARDINAL) is assigned 
  570.            to card; 
  571.  
  572.  wrongFormat if there are characters read or to be read, but these are not in 
  573.            the format of an unsigned whole number; the value of card is not 
  574.            defined; 
  575.  
  576.  endOfLine if no characters are read, the next item being a line mark; the 
  577.            value of card is not defined; 
  578.  
  579.  endOfInput if no characters are read, the input having ended; the value of 
  580.            card is not defined. 
  581.  
  582.  
  583. ΓòÉΓòÉΓòÉ 3.2.2.4. WriteCard - Write a CARDINAL value ΓòÉΓòÉΓòÉ
  584.  
  585. PROCEDURE WriteCard (cid: IOChan.ChanId;
  586.                      card: CARDINAL;
  587.                      width: CARDINAL);
  588. PROCEDURE WriteCard (card: CARDINAL;
  589.                      width: CARDINAL);
  590.  
  591. Modules: WholeIO, SWholeIO 
  592.  
  593. The procedure WriteCard writes the value of card to the output stream 
  594. identified by cid in text form, with leading spaces as required to make the 
  595. number of characters written at least that given by width. In the special case 
  596. of a value of zero for width, exactly one leading space is written. 
  597.  
  598.  
  599. ΓòÉΓòÉΓòÉ 3.2.3. Modules RealIO, SRealIO, LongIO, and SLongIO ΓòÉΓòÉΓòÉ
  600.  
  601. The modules RealIO and LongIO provide facilities for input and output of real 
  602. numbers in decimal text form. 
  603.  
  604. In the case of RealIO, real number parameters are of the type REAL. In the case 
  605. of LongIO, real number parameters are of the type LONGREAL. 
  606.  
  607. The semantics of the two modules are the same, except that when module RealIO 
  608. refers to real number values, these values are of the type REAL, and when 
  609. module LongIO refers to real number values, these values are of the type 
  610. LONGREAL. 
  611.  
  612. NOTE: 
  613.  
  614. The above statement is merely to avoid needless repetition of the semantics for 
  615. the two modules. 
  616.  
  617. The text form of a signed fixed-point real number is 
  618.  
  619. ["+" | "-"], decimal digit, {decimal digit},
  620. [".", {decimal digit}]
  621.  
  622. The text form of a signed floating-point real number is 
  623.  
  624. signed fixed-point real number,
  625. "E"|"e", ["+" | "-"], decimal digit, {decimal digit}
  626.  
  627. The procedures of the module SRealIO behave as the corresponding procedures of 
  628. the module RealIO, except that input is taken from the default input channel, 
  629. and output is sent to the default output channel. 
  630.  
  631. The procedures of the module SLongIO behave as the corresponding procedures of 
  632. the module LongIO, except that input is taken from the default input channel, 
  633. and output is sent to the default output channel. 
  634.  
  635.      ReadReal - Read a real value 
  636.      WriteFloat - Write a real value in floating-point format 
  637.      WriteEng - Write a real value in engineering format 
  638.      WriteFixed - Write a real value in fixed-point format 
  639.      WriteReal - Write a real value 
  640.  
  641.  
  642. ΓòÉΓòÉΓòÉ 3.2.3.1. ReadReal - Read a real value ΓòÉΓòÉΓòÉ
  643.  
  644. PROCEDURE ReadReal (cid: IOChan.ChanId;
  645.                     VAR real: REAL);
  646. PROCEDURE ReadReal (cid: IOChan.ChanId;
  647.                     VAR real: LONGREAL);
  648. PROCEDURE ReadReal (VAR real: REAL);
  649. PROCEDURE ReadReal (VAR real: LONGREAL);
  650.  
  651. Modules: RealIO, SRealIO, LongIO, SLongIO 
  652.  
  653. The procedure ReadReal skips any leading spaces from the input stream 
  654. identified by cid, and then reads characters that form a signed fixed or 
  655. floating point number. The read result for the channel is set to the value 
  656.  
  657.  allRight  if a signed real number is read, and its value is in the range of 
  658.            the type of real; the value of this number is assigned to real; 
  659.  
  660.  outOfRange if a signed real number is read, but its value is out of range of 
  661.            the type of real; the maximum or minimum value of the type of real 
  662.            is assigned to real according to the sign of the number; 
  663.  
  664.  wrongFormat if there are characters read or to be read, but these characters 
  665.            are not in the format of a signed real number; the value of real is 
  666.            not defined; 
  667.  
  668.  endOfLine if no characters are read, the next item being a line mark; the 
  669.            value of real is not defined; 
  670.  
  671.  endOfInput if no characters are read, the input having ended; the value of 
  672.            real is not defined. 
  673.  
  674.  
  675. ΓòÉΓòÉΓòÉ 3.2.3.2. WriteFloat - Write a real value in floating-point format ΓòÉΓòÉΓòÉ
  676.  
  677. PROCEDURE WriteFloat (cid: IOChan.ChanId;
  678.                       real: REAL;
  679.                       sigFigs: CARDINAL;
  680.                       width: CARDINAL);
  681. PROCEDURE WriteFloat (cid: IOChan.ChanId;
  682.                       real: LONGREAL;
  683.                       sigFigs: CARDINAL;
  684.                       width: CARDINAL);
  685. PROCEDURE WriteFloat (real: REAL;
  686.                       sigFigs: CARDINAL;
  687.                       width: CARDINAL);
  688. PROCEDURE WriteFloat (real: LONGREAL;
  689.                       sigFigs: CARDINAL;
  690.                       width: CARDINAL);
  691.  
  692. Modules: RealIO, SRealIO, LongIO, SLongIO 
  693.  
  694. The procedure WriteFloat writes the value of real to the output stream 
  695. identified by cid in floating-point text form, with leading spaces as required 
  696. to make the number of characters written at least that given by width. A sign 
  697. is written only for negative values. In the special case of a value of zero for 
  698. width, exactly one leading space is written. 
  699.  
  700. One significant digit is included in the whole number part. The signed exponent 
  701. part is included only if the exponent value is not zero. If the value of 
  702. sigFigs is greater than zero, that number of significant digits is included, 
  703. otherwise an implementation-defined number of significant digits is included. 
  704. The decimal point is not included if there are no significant digits in the 
  705. fractional part. 
  706.  
  707. The following table gives examples of output by WriteFloat: 
  708.  
  709. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  710.  sigFigs  3923009    39.23009   0.0003923009
  711.  
  712.  1        4E+6       4E+1       4E-4
  713.  
  714.  2        3.9E+6     3.9E+1     3.9E-4
  715.  
  716.  5        3.9230E+6  3.9230E+1  3.9230E-4
  717. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  718.  
  719.  
  720. ΓòÉΓòÉΓòÉ 3.2.3.3. WriteEng - Write a real value in engineering format ΓòÉΓòÉΓòÉ
  721.  
  722. PROCEDURE WriteEng (cid: IOChan.ChanId;
  723.                     real: REAL;
  724.                     sigFigs: CARDINAL;
  725.                     width: CARDINAL);
  726. PROCEDURE WriteEng (cid: IOChan.ChanId;
  727.                     real: LONGREAL;
  728.                     sigFigs: CARDINAL;
  729.                     width: CARDINAL);
  730. PROCEDURE WriteEng (real: REAL;
  731.                     sigFigs: CARDINAL;
  732.                     width: CARDINAL);
  733. PROCEDURE WriteEng (real: LONGREAL;
  734.                     sigFigs: CARDINAL;
  735.                     width: CARDINAL);
  736.  
  737. Modules: RealIO, SRealIO, LongIO, SLongIO 
  738.  
  739. The procedure WriteEng behaves as the procedure WriteFloat except that the 
  740. number is scaled with one to three digits in the whole number part, and with an 
  741. exponent that is a multiple of three. 
  742.  
  743. The following table gives examples of output by WriteEng: 
  744.  
  745. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  746.  sigFigs  3923009    39.23009  0.0003923009
  747.  
  748.  1        4E+6       40        400E-6
  749.  
  750.  2        3.9E+6     39        390E-6
  751.  
  752.  5        3.9230E+6  39.230    392.30E-6
  753. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  754.  
  755.  
  756. ΓòÉΓòÉΓòÉ 3.2.3.4. WriteFixed - Write a real value in fixed-point format ΓòÉΓòÉΓòÉ
  757.  
  758. PROCEDURE WriteFixed (cid: IOChan.ChanId;
  759.                       real: REAL;
  760.                       place: INTEGER;
  761.                       width: CARDINAL);
  762. PROCEDURE WriteFixed (cid: IOChan.ChanId;
  763.                       real: LONGREAL;
  764.                       place: INTEGER;
  765.                       width: CARDINAL);
  766. PROCEDURE WriteFixed (real: REAL;
  767.                       place: INTEGER;
  768.                       width: CARDINAL);
  769. PROCEDURE WriteFixed (real: LONGREAL;
  770.                       place: INTEGER;
  771.                       width: CARDINAL);
  772.  
  773. Modules: RealIO, SRealIO, LongIO, SLongIO 
  774.  
  775. The procedure WriteFixed writes the value of real to the output stream 
  776. identified by cid in fixed-point text form with leading spaces as required to 
  777. make the number of characters written at least that given by width. A sign is 
  778. written only for negative values. In the special case of a value of zero for 
  779. width, exactly one leading space is written. 
  780.  
  781. At least one digit is included in the whole number part. The value is rounded 
  782. to the given value of place relative to the decimal point. The decimal point is 
  783. suppressed if place is less than zero. 
  784.  
  785. The following table gives examples of output by WriteFixed: 
  786.  
  787. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  788.  places  3923009       39.23009  0.0003923009
  789.  
  790.  -5      3920000       0         0
  791.  
  792.  -2      3923010       40        0
  793.  
  794.  -1      3923009       39        0
  795.  
  796.  0       3923009.      39.       0.
  797.  
  798.  1       3923009.0     39.2      0.0
  799.  
  800.  4       3923009.0000  39.2301   0.0004
  801. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  802.  
  803.  
  804. ΓòÉΓòÉΓòÉ 3.2.3.5. WriteReal - Write a real value ΓòÉΓòÉΓòÉ
  805.  
  806. PROCEDURE WriteReal (cid: IOChan.ChanId;
  807.                      real: REAL;
  808.                      width: CARDINAL);
  809. PROCEDURE WriteReal (cid: IOChan.ChanId;
  810.                      real: LONGREAL;
  811.                      width: CARDINAL);
  812. PROCEDURE WriteReal (real: REAL;
  813.                      width: CARDINAL);
  814. PROCEDURE WriteReal (real: LONGREAL;
  815.                      width: CARDINAL);
  816.  
  817. Modules: RealIO, SRealIO, LongIO, SLongIO 
  818.  
  819. If the sign and magnitude of real can be expressed in a field given by width, 
  820. the procedure WriteReal behaves as the procedure WriteFixed, with a value of 
  821. place chosen to fill exactly the remaining field. Otherwise it behaves as the 
  822. procedure WriteFloat, with a value of sigFigs of at least one, limited to those 
  823. that can be included together with the sign and exponent part in the given 
  824. width. 
  825.  
  826. In the special case of a width of zero, the effect is as for the procedure 
  827. WriteFloat with a value of sigFigs equal to zero. 
  828.  
  829.  
  830. ΓòÉΓòÉΓòÉ 3.2.4. Modules RawIO and SRawIO ΓòÉΓòÉΓòÉ
  831.  
  832. The module RawIO provides facilities for direct input and output of data using 
  833. raw operations (i.e. without any interpretation). 
  834.  
  835. The procedures of the module SRawIO behave as the corresponding procedures of 
  836. the module RawIO, except that input is taken from the default input channel, 
  837. and output is sent to the default output channel. 
  838.  
  839.      Read - Read storage units 
  840.      Write - Write storage units 
  841.  
  842.  
  843. ΓòÉΓòÉΓòÉ 3.2.4.1. Read - Read storage units ΓòÉΓòÉΓòÉ
  844.  
  845. PROCEDURE Read (cid: IOChan.ChanId;
  846.                 VAR to: ARRAY OF SYSTEM.LOC);
  847. PROCEDURE Read (VAR to: ARRAY OF SYSTEM.LOC);
  848.  
  849. Modules: RawIO, SRawIO 
  850.  
  851. While the stream identified by cid is not exhausted, the procedure Read reads 
  852. successive storage units from that channel, and assign them without 
  853. interpretation to successive components of to. The read result for the channel 
  854. is set to the value 
  855.  
  856.  allRight  if items are read for all components; 
  857.  
  858.  wrongFormat if some items are read, but not for all components; 
  859.  
  860.  endOfInput if no items are read, the input having ended. 
  861.  
  862.  
  863. ΓòÉΓòÉΓòÉ 3.2.4.2. Write - Write storage units ΓòÉΓòÉΓòÉ
  864.  
  865. PROCEDURE Write (cid: IOChan.ChanId;
  866.                  from: ARRAY OF SYSTEM.LOC);
  867. PROCEDURE Write (from: ARRAY OF SYSTEM.LOC);
  868.  
  869. Modules: RawIO, SRawIO 
  870.  
  871. The procedure Write writes successive components of from to the channel 
  872. identified by cid, as storage units without interpretation. 
  873.  
  874.  
  875. ΓòÉΓòÉΓòÉ 3.2.5. Module IOConsts ΓòÉΓòÉΓòÉ
  876.  
  877. The module IOConsts defines the enumeration type ReadResults used to express 
  878. read results. Programs do not normally need to import from IOConsts directly, 
  879. since client modules define identifiers that correspond to those defined by 
  880. this module. 
  881.  
  882.      ReadResults - Read result identities 
  883.  
  884.  
  885. ΓòÉΓòÉΓòÉ 3.2.5.1. ReadResults - Read result identities ΓòÉΓòÉΓòÉ
  886.  
  887. TYPE
  888.   ReadResults =  (* This type is used to classify the result
  889.                     of an input operation *)
  890.   (
  891.     notKnown,    (* no read result is set *)
  892.     allRight,    (* data is as expected or as required *)
  893.     outOfRange,  (* data cannot be represented *)
  894.     wrongFormat, (* data not in expected format *)
  895.     endOfLine,   (* end of line seen before expected data *)
  896.     endOfInput   (* end of input seen before expected data *)
  897.   );
  898.  
  899. Module IOConsts 
  900.  
  901.  
  902. ΓòÉΓòÉΓòÉ 3.2.6. Modules IOResult and SIOResult ΓòÉΓòÉΓòÉ
  903.  
  904. The module IOResult provides the facility for a program to determine whether 
  905. the last operation to read data from a specified input channel found data in 
  906. the required format. 
  907.  
  908. The procedure of the module SIOResult behaves as the corresponding procedure of 
  909. the module IOResult, except that the read result for the default input channel 
  910. is returned. 
  911.  
  912. NOTE: 
  913.  
  914. The existence of the module IOConsts allows the definition module SIOResult to 
  915. be independent of the modules IOResult and IOChan. 
  916.  
  917.      ReadResults - Read result identities 
  918.      ReadResult - Get read result for channel 
  919.  
  920.  
  921. ΓòÉΓòÉΓòÉ 3.2.6.1. ReadResults - Read result identities ΓòÉΓòÉΓòÉ
  922.  
  923. TYPE
  924.   ReadResults = IOConsts.ReadResults;
  925.  
  926. Modules: IOResult, SIOResult 
  927.  
  928. The type IOConsts.ReadResults is re-exported. 
  929.  
  930.  
  931. ΓòÉΓòÉΓòÉ 3.2.6.2. ReadResult - Get read result for channel ΓòÉΓòÉΓòÉ
  932.  
  933. PROCEDURE ReadResult (cid: IOChan.ChanId): ReadResults;
  934. PROCEDURE ReadResult (): ReadResults;
  935.  
  936. Modules: IOResult, SIOResult 
  937.  
  938. The function procedure ReadResult returns the stored read result for the 
  939. channel identified by cid. 
  940.  
  941.  
  942. ΓòÉΓòÉΓòÉ 3.3. Device-Independent Channel Operations ΓòÉΓòÉΓòÉ
  943.  
  944. The module IOChan provides access to channel operations that are provided in a 
  945. device-independent manner for all channels. 
  946.  
  947. Device-dependent operations (which include operations for opening new channels 
  948. and subsequently closing them) are defined in the definition module for each 
  949. device. 
  950.  
  951.      Module IOChan 
  952.      Module IOChan - Text Operations 
  953.      Module IOChan - Raw Operations 
  954.      Module IOChan - Common Operations 
  955.      Module IOChan - Access to Read Results 
  956.      Module IOChan - Channel Enquiries 
  957.      Module IOChan - Exceptions and Device Errors 
  958.  
  959.  
  960. ΓòÉΓòÉΓòÉ 3.3.1. Module IOChan ΓòÉΓòÉΓòÉ
  961.  
  962. The module IOChan defines the hidden type ChanId that is used to identify 
  963. channels throughout the input/output library, and provides facilities for 
  964. device-independent access to operations supported by the device to which a 
  965. channel is connected. 
  966.  
  967.      ChanId - Channel identity 
  968.      InvalidChan - Get an invalid channel id 
  969.  
  970.  
  971. ΓòÉΓòÉΓòÉ 3.3.1.1. ChanId - Channel identity ΓòÉΓòÉΓòÉ
  972.  
  973. TYPE
  974.   ChanId;
  975.  
  976. Module IOChan 
  977.  
  978. Values of this type are used to identify channels throughout the input/output 
  979. library. 
  980.  
  981.  
  982. ΓòÉΓòÉΓòÉ 3.3.1.2. InvalidChan - Get an invalid channel id ΓòÉΓòÉΓòÉ
  983.  
  984. PROCEDURE InvalidChan (): ChanId;
  985.  
  986. Module IOChan 
  987.  
  988. The function procedure InvalidChan returns the identity of the invalid channel. 
  989.  
  990. NOTE: 
  991.  
  992. The invalid channel is a channel on which no data transfer operations are 
  993. available; enquiries on the invalid channel indicate that this is the case. The 
  994. identity of the invalid channel can be used to initialize variables of the type 
  995. ChanId. 
  996.  
  997.  
  998. ΓòÉΓòÉΓòÉ 3.3.2. Module IOChan - Text Operations ΓòÉΓòÉΓòÉ
  999.  
  1000. Each of the following procedures invokes a corresponding operation for the 
  1001. device associated with the given channel. If the associated device supports the 
  1002. operation on the channel, the behaviour of the procedure conforms with the 
  1003. given description. The full behaviour is defined separately for each device. 
  1004.  
  1005. These device operations produce a text stream. A text stream is a sequence of 
  1006. items, each of which corresponds either to a character or a line mark. The 
  1007. sequence may be empty. 
  1008.  
  1009. The text operations provided by a device module perform any necessary 
  1010. translation between the internal representation (as a sequence of characters 
  1011. and line marks) and the external representation used by the source or 
  1012. destination. This may involve, for example, translation to and from escape 
  1013. sequences used in a coded character set, mapping between the external and 
  1014. internal representation of lines, or the interpretation of format effectors. 
  1015.  
  1016. The interpretation of control characters is implementation-defined. The 
  1017. exception textParseError occurs (but need not be raised) if input data does not 
  1018. correspond to a character or line mark. 
  1019.  
  1020. If the device does not support the operation on the channel, it raises the 
  1021. exception notAvailable. 
  1022.  
  1023.      Look - Invoke Look operation 
  1024.      Skip - Invoke Skip operation 
  1025.      SkipLook - Invoke SkipLook operation 
  1026.      WriteLn - Invoke WriteLn operation 
  1027.      TextRead - Invoke TextRead operation 
  1028.      TextWrite - Invoke TextWrite operation 
  1029.  
  1030.  
  1031. ΓòÉΓòÉΓòÉ 3.3.2.1. Look - Invoke Look operation ΓòÉΓòÉΓòÉ
  1032.  
  1033. PROCEDURE Look (cid: ChanId;
  1034.                 VAR ch: CHAR;
  1035.                 VAR res: IOConsts.ReadResults);
  1036.  
  1037. Module IOChan 
  1038.  
  1039. The procedure Look invokes the Look operation for the device that is associated 
  1040. with the channel identified by cid. 
  1041.  
  1042. NOTE: 
  1043.  
  1044. If supported on the channel, the device Look operation attempts to examine the 
  1045. next item in the input stream for the channel identified by cid, without 
  1046. removing it. If the next item is a character, its value is assigned to ch; 
  1047. otherwise, the value of ch is not defined. res is set to the same value as the 
  1048. stored read result for the channel cid, this being: 
  1049.  
  1050.  allRight  if a character is seen next; 
  1051.  
  1052.  endOfLine if no character is seen, the next item being a line mark; 
  1053.  
  1054.  endOfInput if no character is seen, the input having ended. 
  1055.  
  1056.  
  1057. ΓòÉΓòÉΓòÉ 3.3.2.2. Skip - Invoke Skip operation ΓòÉΓòÉΓòÉ
  1058.  
  1059. PROCEDURE Skip (cid: ChanId);
  1060.  
  1061. Module IOChan 
  1062.  
  1063. The procedure Skip invokes the Skip operation for the device that is associated 
  1064. with the channel identified by cid. 
  1065.  
  1066. NOTE: 
  1067.  
  1068. If supported on the channel, the device Skip operation attempts to remove the 
  1069. next item in the input stream for the channel identified by cid. If there is no 
  1070. next item, the end of the input stream having been reached, the exception 
  1071. skipAtEnd is raised; otherwise the next character or line mark in the stream is 
  1072. removed, and the stored read result for the channel cid is set to the value 
  1073. allRight. 
  1074.  
  1075.  
  1076. ΓòÉΓòÉΓòÉ 3.3.2.3. SkipLook - Invoke SkipLook operation ΓòÉΓòÉΓòÉ
  1077.  
  1078. PROCEDURE SkipLook (cid: ChanId;
  1079.                     VAR ch: CHAR;
  1080.                     VAR res: IOConsts.ReadResults);
  1081.  
  1082. Module IOChan 
  1083.  
  1084. The procedure SkipLook invokes the SkipLook operation for the device that is 
  1085. associated with the channel identified by cid. 
  1086.  
  1087. NOTE: 
  1088.  
  1089. If supported on the channel, the device SkipLook operation attempts to remove 
  1090. the next item in the input stream for the channel identified by cid and then to 
  1091. examine the following item without removing it. If there is no next item, the 
  1092. end of the input stream having been reached, the exception skipAtEnd is raised; 
  1093. otherwise the next character or line mark in the stream is removed. If this is 
  1094. followed by a character as the next item in the stream, its value is assigned 
  1095. to ch, without removing the character from the stream; otherwise, the value of 
  1096. ch is not defined. res is set to the same value as the stored read result for 
  1097. the channel cid, this being: 
  1098.  
  1099.  allRight  if a character is seen next; 
  1100.  
  1101.  endOfLine if no character is seen, the next item being a line mark; 
  1102.  
  1103.  endOfInput if no character is seen, the input having ended. 
  1104.  
  1105.  
  1106. ΓòÉΓòÉΓòÉ 3.3.2.4. WriteLn - Invoke WriteLn operation ΓòÉΓòÉΓòÉ
  1107.  
  1108. PROCEDURE WriteLn (cid: ChanId);
  1109.  
  1110. Module IOChan 
  1111.  
  1112. The procedure WriteLn invokes the WriteLn operation for the device that is 
  1113. associated with the channel identified by cid. 
  1114.  
  1115. NOTE: If supported on the channel, the device WriteLn operation writes a line 
  1116. mark to the output stream identified by cid. 
  1117.  
  1118.  
  1119. ΓòÉΓòÉΓòÉ 3.3.2.5. TextRead - Invoke TextRead operation ΓòÉΓòÉΓòÉ
  1120.  
  1121. PROCEDURE TextRead (cid: ChanId;
  1122.                     to: SYSTEM.ADDRESS;
  1123.                     maxChars: CARDINAL;
  1124.                     VAR charsRead: CARDINAL);
  1125.  
  1126. Module IOChan 
  1127.  
  1128. The procedure TextRead invokes the TextRead operation for the device that is 
  1129. associated with the channel identified by cid. 
  1130.  
  1131. NOTES: 
  1132.  
  1133.      If supported on the channel, the device TextRead operation reads at most 
  1134.       maxChars characters from the current line on the input stream for the 
  1135.       channel identified by cid, and assigns their values to successive 
  1136.       components of an array variable of the character type for which the 
  1137.       address of the first component is to. The number of characters read is 
  1138.       assigned to charsRead. The read result for the channel cid is set to the 
  1139.       value 
  1140.  
  1141.       allRight       if `maxChars = charsRead = 0' or (`maxChars > 0' and 
  1142.                      `charsRead > 0'); 
  1143.  
  1144.       endOfLine      if `maxChars > 0' and `charsRead = 0' , the next item 
  1145.                      being a line mark; 
  1146.  
  1147.       endOfInput     if `maxChars > 0' and `charsRead = 0', the input having 
  1148.                      ended. 
  1149.  
  1150.      The intention is to allow `sub-arrays' to be selected, by passing the 
  1151.       address of a starting component within a larger array. An exception 
  1152.       occurs, but need not be raised, if the call leads to an attempt to access 
  1153.       a non-existent component of the larger array. 
  1154.  
  1155.  
  1156. ΓòÉΓòÉΓòÉ 3.3.2.6. TextWrite - Invoke TextWrite operation ΓòÉΓòÉΓòÉ
  1157.  
  1158. PROCEDURE TextWrite (cid: ChanId;
  1159.                      from: SYSTEM.ADDRESS;
  1160.                      charsToWrite: CARDINAL);
  1161.  
  1162. Module IOChan 
  1163.  
  1164. The procedure TextWrite invokes the TextWrite operation for the device that is 
  1165. associated with the channel identified by cid. 
  1166.  
  1167. NOTES: 
  1168.  
  1169.      If supported on the channel, the device TextWrite operation copies 
  1170.       charsToWrite characters, from successive components of an array variable 
  1171.       of the character type, for which the address of the first component is 
  1172.       from, to the output stream for the channel identified by cid. Copying 
  1173.       starts from the index given by offset. 
  1174.  
  1175.      The intention is to allow `sub-arrays' to be selected, by passing the 
  1176.       address of a starting component within a larger array. An exception 
  1177.       occurs, but need not be raised, if the call leads to an attempt to access 
  1178.       a non-existent component of the larger array. 
  1179.  
  1180.  
  1181. ΓòÉΓòÉΓòÉ 3.3.3. Module IOChan - Raw Operations ΓòÉΓòÉΓòÉ
  1182.  
  1183. Each of the following procedures invokes a corresponding operation for the 
  1184. device associated with the given channel. If the associated device supports the 
  1185. operation on the channel, the behaviour of the procedure conforms with the 
  1186. given description. The full behaviour is defined for each device module. 
  1187.  
  1188. The raw operations provided by a device module transfer data location by 
  1189. location with no translation or interpretation. 
  1190.  
  1191. If the device does not support the operation on the channel, it raises the 
  1192. exception notAvailable. 
  1193.  
  1194.      RawRead - Invoke RawRead operation 
  1195.      RawWrite - Invoke RawWrite operation 
  1196.  
  1197.  
  1198. ΓòÉΓòÉΓòÉ 3.3.3.1. RawRead - Invoke RawRead operation ΓòÉΓòÉΓòÉ
  1199.  
  1200. PROCEDURE RawRead (cid: ChanId;
  1201.                    to: SYSTEM.ADDRESS;
  1202.                    maxLocs: CARDINAL;
  1203.                    VAR locsRead: CARDINAL);
  1204.  
  1205. Module IOChan 
  1206.  
  1207. The procedure RawRead invokes the RawRead operation for the device that is 
  1208. associated with the channel identified by cid. 
  1209.  
  1210. NOTES 
  1211.  
  1212.      If supported on the channel, the device RawRead operation reads at most 
  1213.       maxLocs items from the input stream for the channel identified by cid, 
  1214.       and assigns their values to successive components of an array variable of 
  1215.       the location type for which the address of the first component is to. The 
  1216.       number of items read is assigned to locsRead. The read result for the 
  1217.       channel cid is set to the value 
  1218.  
  1219.       allRight       if (`maxLocs = locsRead = 0') or (`maxLocs > 0 and 
  1220.                      `locsRead > 0') 
  1221.  
  1222.       endOfInput     if `maxLocs > 0' and `locsRead = 0' 
  1223.  
  1224.      The intention is to allow `sub-arrays' to be selected, by passing the 
  1225.       address of a starting component within a larger array. An exception 
  1226.       occurs, but need not be raised, if the call leads to an attempt to access 
  1227.       a non-existent component of the larger array. 
  1228.  
  1229.  
  1230. ΓòÉΓòÉΓòÉ 3.3.3.2. RawWrite - Invoke RawWrite operation ΓòÉΓòÉΓòÉ
  1231.  
  1232. PROCEDURE RawWrite (cid: ChanId;
  1233.                     from: SYSTEM.ADDRESS;
  1234.                     locsToWrite: CARDINAL);
  1235.  
  1236. Module IOChan 
  1237.  
  1238. The procedure RawWrite invokes the RawWrite operation for the device that is 
  1239. associated with the channel identified by cid. 
  1240.  
  1241. NOTES: 
  1242.  
  1243.      If supported on the channel, the device RawWrite operation copies 
  1244.       locsToWrite items, from successive components of an array variable of the 
  1245.       character type, for which the address of the first component is from, to 
  1246.       the output stream for the channel identified by cid. Copying starts from 
  1247.       the index given by offset. 
  1248.  
  1249.      The intention is to allow `sub-arrays' to be selected, by passing the 
  1250.       address of a starting component within a larger array. An exception 
  1251.       occurs, but need not be raised, if the call leads to an attempt to access 
  1252.       a non-existent component of the larger array. 
  1253.  
  1254.  
  1255. ΓòÉΓòÉΓòÉ 3.3.4. Module IOChan - Common Operations ΓòÉΓòÉΓòÉ
  1256.  
  1257. Each of the following procedures invokes a corresponding operation for the 
  1258. device associated with the given channel. The behaviour of the procedure 
  1259. conforms with the given description. The full behaviour is defined for each 
  1260. device module. 
  1261.  
  1262.      GetName - Invoke GetName operation 
  1263.      Reset - Invoke Reset operation 
  1264.      Flush - Invoke Flush operation 
  1265.  
  1266.  
  1267. ΓòÉΓòÉΓòÉ 3.3.4.1. GetName - Invoke GetName operation ΓòÉΓòÉΓòÉ
  1268.  
  1269. PROCEDURE GetName (cid: ChanId;
  1270.                    VAR s: ARRAY OF CHAR);
  1271.  
  1272. Module IOChan 
  1273.  
  1274. The procedure GetName invokes the GetName operation for the device that is 
  1275. associated with the channel identified by cid. 
  1276.  
  1277. NOTES: 
  1278.  
  1279.      The device GetName operation copies to s (as a string value) a name 
  1280.       associated with the channel identified by cid. 
  1281.  
  1282.      The name is truncated if the capacity of s is inadequate. 
  1283.  
  1284.  
  1285. ΓòÉΓòÉΓòÉ 3.3.4.2. Reset - Invoke Reset operation ΓòÉΓòÉΓòÉ
  1286.  
  1287. PROCEDURE Reset (cid: ChanId);
  1288.  
  1289. Module IOChan 
  1290.  
  1291. The procedure Reset invokes the Reset operation for the device that is 
  1292. associated with the channel identified by cid. 
  1293.  
  1294. NOTE: 
  1295.  
  1296. The device Reset operation resets the device associated with the channel 
  1297. identified by cid to a state defined by the device module. 
  1298.  
  1299.  
  1300. ΓòÉΓòÉΓòÉ 3.3.4.3. Flush - Invoke Flush operation ΓòÉΓòÉΓòÉ
  1301.  
  1302. PROCEDURE Flush (cid: ChanId);
  1303.  
  1304. Module IOChan 
  1305.  
  1306. The procedure Flush invokes the Flush operation for the device that is 
  1307. associated with the channel identified by cid. 
  1308.  
  1309. NOTE: 
  1310.  
  1311. The device Flush operation flushes any data buffered by the device module out 
  1312. to the destination associated with cid. 
  1313.  
  1314.  
  1315. ΓòÉΓòÉΓòÉ 3.3.5. Module IOChan - Access to Read Results ΓòÉΓòÉΓòÉ
  1316.  
  1317. Higher-level data input procedures, for units such as strings and numerals, may 
  1318. alter the read result for a channel to indicate success or a particular kind of 
  1319. failure of interpretation. The result can be recovered, if necessary, by the 
  1320. caller of the data input procedure. 
  1321.  
  1322.      SetReadResult - Set read result for channel 
  1323.      ReadResult - Get read result for channel 
  1324.  
  1325.  
  1326. ΓòÉΓòÉΓòÉ 3.3.5.1. SetReadResult - Set read result for channel ΓòÉΓòÉΓòÉ
  1327.  
  1328. PROCEDURE SetReadResult (cid: ChanId;
  1329.                          res: IOConsts.ReadResults);
  1330.  
  1331. Module IOChan 
  1332.  
  1333. The procedure SetReadResult sets the read result for the channel identified by 
  1334. cid to the value given by res. 
  1335.  
  1336.  
  1337. ΓòÉΓòÉΓòÉ 3.3.5.2. ReadResult - Get read result for channel ΓòÉΓòÉΓòÉ
  1338.  
  1339. PROCEDURE ReadResult (cid: ChanId): IOConsts.ReadResults;
  1340.  
  1341. Module IOChan 
  1342.  
  1343. The function procedure ReadResult returns the stored read result for the 
  1344. channel identified by cid. 
  1345.  
  1346.  
  1347. ΓòÉΓòÉΓòÉ 3.3.6. Module IOChan - Channel Enquiries ΓòÉΓòÉΓòÉ
  1348.  
  1349.      CurrentFlags - Get current flags for channel 
  1350.  
  1351.  
  1352. ΓòÉΓòÉΓòÉ 3.3.6.1. CurrentFlags - Get current flags for channel ΓòÉΓòÉΓòÉ
  1353.  
  1354. PROCEDURE CurrentFlags (cid: ChanId): ChanConsts.FlagSet;
  1355.  
  1356. Module IOChan 
  1357.  
  1358. The function procedure CurrentFlags returns the set of flags that currently 
  1359. apply to the channel identified by cid, as defined for the associated device. 
  1360.  
  1361.  
  1362. ΓòÉΓòÉΓòÉ 3.3.7. Module IOChan - Exceptions and Device Errors ΓòÉΓòÉΓòÉ
  1363.  
  1364. The device-independent exceptions raised by the input/output library are 
  1365. identified by the values of the enumeration type ChanExceptions: 
  1366.  
  1367.      ChanExceptions - Channel exceptions identities 
  1368.      IsChanException - Query exceptional state 
  1369.      ChanException - Query exception id 
  1370.      DeviceErrNum - Device error number 
  1371.      DeviceError - Get device error number 
  1372.  
  1373.  
  1374. ΓòÉΓòÉΓòÉ 3.3.7.1. ChanExceptions - Channel exceptions identities ΓòÉΓòÉΓòÉ
  1375.  
  1376. TYPE
  1377.   ChanExceptions =
  1378.     (wrongDevice,
  1379.        (* device specific operation on wrong device *)
  1380.      notAvailable,
  1381.        (* operation attempted is not available on the channel *)
  1382.      skipAtEnd,
  1383.        (* attempt to skip data from a stream that has ended *)
  1384.      softDeviceError,
  1385.        (* device specific recoverable error *)
  1386.      hardDeviceError,
  1387.        (* device specific non-recoverable error *)
  1388.      textParseError,
  1389.        (* input data does not correspond to a character
  1390.           or line mark - optional detection *)
  1391.      notAChannel
  1392.        (* given value does not identify a channel -
  1393.           optional detection *)
  1394.    );
  1395.  
  1396. Module IOChan 
  1397.  
  1398. NOTE: 
  1399.  
  1400. The detection of the exceptions textParseError and notAChannel is 
  1401. implementation-defined. 
  1402.  
  1403.  
  1404. ΓòÉΓòÉΓòÉ 3.3.7.2. IsChanException - Query exceptional state ΓòÉΓòÉΓòÉ
  1405.  
  1406. PROCEDURE IsChanException (): BOOLEAN;
  1407.  
  1408. Module IOChan 
  1409.  
  1410. If the calling coroutine is in the state of exceptional execution because of 
  1411. the raising of an exception from ChanExceptions, the function procedure 
  1412. IsChanException returns TRUE; otherwise it returns FALSE. 
  1413.  
  1414.  
  1415. ΓòÉΓòÉΓòÉ 3.3.7.3. ChanException - Query exception id ΓòÉΓòÉΓòÉ
  1416.  
  1417. PROCEDURE ChanException (): ChanExceptions;
  1418.  
  1419. Module IOChan 
  1420.  
  1421. If the calling coroutine is in the state of exceptional execution because of 
  1422. the raising of an exception from ChanExceptions, the function procedure 
  1423. ChanException returns the value that identifies the raised exception; otherwise 
  1424. the language exception exException is raised. 
  1425.  
  1426.  
  1427. ΓòÉΓòÉΓòÉ 3.3.7.4. DeviceErrNum - Device error number ΓòÉΓòÉΓòÉ
  1428.  
  1429. TYPE
  1430.   DeviceErrNum = INTEGER;
  1431.  
  1432. Module IOChan 
  1433.  
  1434. Values of the type DeviceErrNum are used to identufy the implementation-defined 
  1435. error number for a chennel in the device exception handler. 
  1436.  
  1437. See DeviceError procedure. 
  1438.  
  1439.  
  1440. ΓòÉΓòÉΓòÉ 3.3.7.5. DeviceError - Get device error number ΓòÉΓòÉΓòÉ
  1441.  
  1442. PROCEDURE DeviceError (cid: ChanId): DeviceErrNum;
  1443.  
  1444. Module IOChan 
  1445.  
  1446. The function procedure DeviceError returns the error number stored by the 
  1447. device module for the channel identified by cid, provided that a device error 
  1448. exception has been raised during an operation on that channel; otherwise the 
  1449. value of the call is not defined. 
  1450.  
  1451. NOTE: 
  1452.  
  1453. When a device procedure detects a device error, it raises the exception 
  1454. softDeviceError or hardDeviceError. If these exceptions are handled, the 
  1455. procedure DeviceError may be used to discover the implementation-defined error 
  1456. number stored by the device module for the channel that was in use when the 
  1457. device error occurred. 
  1458.  
  1459.  
  1460. ΓòÉΓòÉΓòÉ 3.4. Obtaining Channels from Device Modules ΓòÉΓòÉΓòÉ
  1461.  
  1462. Separate device modules are defined that provide a program with the facility to 
  1463. obtain a new channel, connected either to a sequential stream, a rewindable 
  1464. sequential file, a random access file, or a terminal device. 
  1465.  
  1466. A request to obtain a channel is made by calling an appropriate `open 
  1467. procedure', in general supplying a name that identifies the source or 
  1468. destination to which the connection is to be made. 
  1469.  
  1470. The required input/output operations are specified using combinations of flags 
  1471. that are defined in terms of constants imported from the module ChanConsts. 
  1472.  
  1473. An open procedure returns a parameter of an enumeration type (exported from the 
  1474. module ChanConsts) that indicates the success, or otherwise, of the request. 
  1475.  
  1476. Each of these device modules defines a predicate allowing a check to be made 
  1477. that a given channel was opened by that module, as well as a `close procedure' 
  1478. that allows a program to break the connection and release the channel. 
  1479.  
  1480. Procedures are also provided for device-dependent operations, such as setting 
  1481. the read/write position on a random access file. 
  1482.  
  1483. A further device module is defined to allow access to the program arguments 
  1484. over a pre-opened channel. 
  1485.  
  1486.      Module ChanConsts 
  1487.      Module StreamFile 
  1488.      Module SeqFile 
  1489.      Module RndFile 
  1490.      Module TermFile 
  1491.      Module ProgramArgs 
  1492.  
  1493.  
  1494. ΓòÉΓòÉΓòÉ 3.4.1. Module ChanConsts ΓòÉΓòÉΓòÉ
  1495.  
  1496. The module ChanConsts defines common types and values for use with open 
  1497. procedures. Programs do not normally need to import from ChanConsts directly, 
  1498. since device modules define identifiers that correspond to those defined by 
  1499. this module. 
  1500.  
  1501.      ChanFlags - Channel open flags 
  1502.      FlagSet - Channel open flags set 
  1503.      OpenResults - Results of an open request 
  1504.      The Use of ChanConsts 
  1505.  
  1506.  
  1507. ΓòÉΓòÉΓòÉ 3.4.1.1. ChanFlags - Channel open flags ΓòÉΓòÉΓòÉ
  1508.  
  1509. TYPE
  1510.   ChanFlags =
  1511.   ( readFlag,
  1512.       (* input operations are requested/available *)
  1513.     writeFlag,
  1514.       (* output operations are requested/available *)
  1515.     oldFlag,
  1516.       (* a file may/must/did exist
  1517.          before the channel is opened *)
  1518.     textFlag,
  1519.       (* text operations are requested/available *)
  1520.     rawFlag,
  1521.       (* raw operations are requested/available *)
  1522.     interactiveFlag,
  1523.       (* interactive use is requested/applies *)
  1524.     echoFlag
  1525.       (* echoing by interactive device on removal of characters
  1526.          from input stream requested/applies *)
  1527.   );
  1528.  
  1529. Module ChanConsts 
  1530.  
  1531. The elements of the enumeration type ChanFlags identify channel flags that are 
  1532. specified when a channel is opened and can be obtained for an open channel. 
  1533.  
  1534. NOTE: 
  1535.  
  1536. The type ??? is used in actual calls. 
  1537.  
  1538.  
  1539. ΓòÉΓòÉΓòÉ 3.4.1.2. FlagSet - Channel open flags set ΓòÉΓòÉΓòÉ
  1540.  
  1541.   FlagSet = SET OF ChanFlags;
  1542.  
  1543. CONST
  1544.   read = FlagSet{readFlag};
  1545.     (* input operations are requested/available *)
  1546.   write = FlagSet{writeFlag};
  1547.     (* output operations are requested/available *)
  1548.   old = FlagSet{oldFlag};
  1549.     (* a file may/must/did exist
  1550.        before the channel is opened *)
  1551.   text = FlagSet{textFlag};
  1552.     (* text operations are requested/available *)
  1553.   raw = FlagSet{rawFlag};
  1554.     (* raw operations are requested/available *)
  1555.   interactive = FlagSet{interactiveFlag};
  1556.     (* interactive use is requested/applies *)
  1557.   echo = FlagSet{echoFlag};
  1558.     (* echoing by interactive device on removal of characters
  1559.        from input stream requested/applies *)
  1560.  
  1561. Module ChanConsts 
  1562.  
  1563. Values of the type FlagSet are used in the calls to channel open procedures. 
  1564. Singleton values of FlagSet are provided for convinience. For example, read + 
  1565. write can be used instead of FlagSet{read,write}. 
  1566.  
  1567.  
  1568. ΓòÉΓòÉΓòÉ 3.4.1.3. OpenResults - Results of an open request ΓòÉΓòÉΓòÉ
  1569.  
  1570. TYPE
  1571.   OpenResults =
  1572.   ( opened,
  1573.       (* the open succeeded as requested *)
  1574.     wrongNameFormat,
  1575.       (* given name is in the wrong format
  1576.          for the implementation *)
  1577.     wrongFlags,
  1578.       (* given flags include a value
  1579.          that does not apply to the device *)
  1580.     tooManyOpen,
  1581.       (* this device cannot support any more open channels *)
  1582.     outOfChans,
  1583.       (* no more channels can be allocated *)
  1584.     wrongPermissions,
  1585.       (* file or directory permissions do not allow request *)
  1586.     noRoomOnDevice,
  1587.       (* storage limits on the device prevent the open *)
  1588.     noSuchFile,
  1589.       (* a needed file does not exist *)
  1590.     fileExists,
  1591.       (* a file of the given name already exists
  1592.          when a new one is required *)
  1593.     wrongFileType,
  1594.       (* the file is of the wrong type to support
  1595.          the required operations *)
  1596.     noTextOperations,
  1597.       (* text operations have been requested,
  1598.          but are not supported *)
  1599.     noRawOperations,
  1600.       (* raw operations have been requested,
  1601.          but are not supported *)
  1602.     noMixedOperations,
  1603.       (* text and raw operations have been requested, but they
  1604.          are not supported in combination *)
  1605.     alreadyOpen,
  1606.       (* the source/destination is already open
  1607.          for operations not supported in combination
  1608.          with the requested operations *)
  1609.     otherProblem
  1610.       (* open failed for some other reason *)
  1611.   );
  1612.  
  1613. Module ChanConsts 
  1614.  
  1615. The elements of the enumeration type OpenResults identify possible results of 
  1616. an open request. 
  1617.  
  1618.  
  1619. ΓòÉΓòÉΓòÉ 3.4.1.4. The Use of ChanConsts ΓòÉΓòÉΓòÉ
  1620.  
  1621. To save repetition in the natural language definition of the device modules, 
  1622. the meaning given to some values of FlagSet and OpenResults is defined here. 
  1623. The meaning of the other flags is given for the open operations to which they 
  1624. apply. 
  1625.  
  1626. In a call of a device module open procedure that has a request parameter of the 
  1627. type FlagSet and a result parameter of the type OpenResults: 
  1628.  
  1629. If the result is opened, the following operations are provided for the opened 
  1630. channel for the combinations of request flags shown: 
  1631.  
  1632. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  1633.        read        write
  1634.  
  1635.  text  text input  text output  as defined for the device
  1636.  
  1637.  raw   raw input   raw output   as defined for the device
  1638. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  1639.  
  1640. NOTE: 
  1641.  
  1642. The supplied flags specify the minimal functionality that must be available for 
  1643. the open operation to succeed. Implementations are free to allow operations in 
  1644. addition to those specified in the request flags provided that these are 
  1645. reflected in the enquiry flags returned for the channel. 
  1646.  
  1647. If the result is other than opened, the channel parameter is assigned the value 
  1648. identifying the invalid channel, on which no input/output operations are 
  1649. provided. The result is chosen according to the following table: 
  1650.  
  1651. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  1652.  wrongNameFormat    if the given name is not in the format defined for the implementation
  1653.  
  1654.  wrongFlags         if the given flags include a value that does not apply to the device
  1655.  
  1656.  tooManyOpen        if the device cannot support any more open channels
  1657.  
  1658.  outOfChans         if no more channels can be allocated
  1659.  
  1660.  wrongPermissions   if file or directory permissions do not allow the request to be met
  1661.  
  1662.  noRoomOnDevice     if storage limits on the device do not allow the request to be met
  1663.  
  1664.  noSuchFile         if a needed file does not exist
  1665.  
  1666.  fileExists         if a file of the given name already exists when a new one is required
  1667.  
  1668.  wrongFileType      if the named file is of the wrong type to support the required operations
  1669.  
  1670.  noTextOperations   if text operations have been requested, but are not supported by the device
  1671.  
  1672.  noRawOperations    if raw operations have been requested, but are not supported by the device
  1673.  
  1674.  noMixedOperations  if text and raw operations have been requested, but they are not supported in combination by the device
  1675.  
  1676.  alreadyOpen        if the source/destination is already open for operations that are not supported in combination with the operations now requested
  1677.  
  1678.  otherProblem       if the open failed for a reason other than the above
  1679. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  1680.  
  1681.  
  1682. ΓòÉΓòÉΓòÉ 3.4.2. Module StreamFile ΓòÉΓòÉΓòÉ
  1683.  
  1684. The module StreamFile provides facilities for obtaining and releasing channels 
  1685. that are connected to named sources and/or destinations for independent 
  1686. sequential data streams. 
  1687.  
  1688. The types IOChan.ChanId, ChanConsts.FlagSet, and ChanConsts.OpenResults are 
  1689. re-expored. The singleton values of the type FlagSet are declared for 
  1690. convinience: 
  1691.  
  1692. TYPE
  1693.   ChanId = IOChan.ChanId;
  1694.   FlagSet = ChanConsts.FlagSet;
  1695.   OpenResults = ChanConsts.OpenResults;
  1696.  
  1697. CONST
  1698.   read = FlagSet{ChanConsts.readFlag};
  1699.     (* input operations are requested/available *)
  1700.   write = FlagSet{ChanConsts.writeFlag};
  1701.     (* output operations are requested/available *)
  1702.   old = FlagSet{ChanConsts.oldFlag};
  1703.     (* a file may/must/did exist
  1704.        before the channel is opened *)
  1705.   text = FlagSet{ChanConsts.textFlag};
  1706.     (* text operations are requested/available *)
  1707.   raw = FlagSet{ChanConsts.rawFlag};
  1708.     (* raw operations are requested/available *)
  1709.  
  1710. In a request to open a sequential stream, the flags read, write, old, text, and 
  1711. raw apply. If raw is not included in the request parameter flags, inclusion of 
  1712. text is implied. 
  1713.  
  1714.      Open - Open sequential stream 
  1715.      IsStreamFile - Query whether stream is sequential 
  1716.      Close - Close sequential stream 
  1717.  
  1718.  
  1719. ΓòÉΓòÉΓòÉ 3.4.2.1. Open - Open sequential stream ΓòÉΓòÉΓòÉ
  1720.  
  1721. PROCEDURE Open (VAR cid: ChanId;
  1722.                 name: ARRAY OF CHAR;
  1723.                 flags: FlagSet;
  1724.                 VAR res: OpenResults);
  1725.  
  1726. Module StreamFile 
  1727.  
  1728. If successful, the procedure Open assigns to cid the identity of a channel that 
  1729. is connected to a sequential stream specified by name, and the value opened is 
  1730. assigned to res. 
  1731.  
  1732. If write is not included in flags, inclusion of read is implied; if read is 
  1733. given or implied, inclusion of old is implied; a source of the given name has 
  1734. to already exist if the call is to succeed. 
  1735.  
  1736. If write is included, a destination of the given name has to not already exist, 
  1737. unless the flag old is given or implied. 
  1738.  
  1739. If a channel cannot be opened as required, the value of res indicates the 
  1740. reason, and cid identifies the invalid channel. 
  1741.  
  1742. NOTE: 
  1743.  
  1744. Distinct modes in combination with text and/or raw are given by the following 
  1745. equivalent sets of flags: 
  1746.  
  1747.      read from an existing source: read old read+old 
  1748.  
  1749.      write to a new destination: write 
  1750.  
  1751.      write to a new or old destination: write+old 
  1752.  
  1753.      read/write an existing source/destination: read+write read+write+old 
  1754.  
  1755.  
  1756. ΓòÉΓòÉΓòÉ 3.4.2.2. IsStreamFile - Query whether stream is sequential ΓòÉΓòÉΓòÉ
  1757.  
  1758. PROCEDURE IsStreamFile (cid: ChanId): BOOLEAN;
  1759.  
  1760. Module StreamFile 
  1761.  
  1762. The function procedure IsStreamFile returns TRUE if the channel identified by 
  1763. cid is open to a sequential stream, and FALSE otherwise. 
  1764.  
  1765.  
  1766. ΓòÉΓòÉΓòÉ 3.4.2.3. Close - Close sequential stream ΓòÉΓòÉΓòÉ
  1767.  
  1768. PROCEDURE Close (VAR cid: ChanId);
  1769.  
  1770. Module StreamFile 
  1771.  
  1772. If the channel identified by cid is open to a sequential stream, the procedure 
  1773. Close closes the channel and assigns the value identifying the invalid channel 
  1774. to cid; otherwise, the exception wrongDevice is raised. 
  1775.  
  1776.  
  1777. ΓòÉΓòÉΓòÉ 3.4.3. Module SeqFile ΓòÉΓòÉΓòÉ
  1778.  
  1779. The module SeqFile provides facilities for obtaining and releasing channels 
  1780. that are connected to named rewindable sequential stored files. 
  1781.  
  1782. If opened for both writing and reading, data written to the file may be read 
  1783. back from the start of the file. Rewriting from the start of the file causes 
  1784. the previous contents to be lost. 
  1785.  
  1786. The types IOChan.ChanId, ChanConsts.FlagSet, and ChanConsts.OpenResults are 
  1787. re-expored. The singleton values of the type FlagSet are declared for 
  1788. convinience: 
  1789.  
  1790. TYPE
  1791.   ChanId = IOChan.ChanId;
  1792.   FlagSet = ChanConsts.FlagSet;
  1793.   OpenResults = ChanConsts.OpenResults;
  1794.  
  1795. CONST
  1796.   read = FlagSet{ChanConsts.readFlag};
  1797.     (* input operations are requested/available *)
  1798.   write = FlagSet{ChanConsts.writeFlag};
  1799.     (* output operations are requested/available *)
  1800.   old = FlagSet{ChanConsts.oldFlag};
  1801.     (* a file may/must/did exist before the channel is opened *)
  1802.   text = FlagSet{ChanConsts.textFlag};
  1803.     (* text operations are requested/available *)
  1804.   raw = FlagSet{ChanConsts.rawFlag};
  1805.     (* raw operations are requested/available *)
  1806.  
  1807. In a request to open a rewindable sequential file, the flags read, write, old, 
  1808. text, and raw apply. If raw is not included in the request parameter flags, 
  1809. inclusion of text is implied. 
  1810.  
  1811. Channels open to rewindable sequential files may be in input mode or in output 
  1812. mode. In input mode, only input operations are available, 
  1813. `(IOChan.Flags()*(read+write) = read)' is true, and an attempt to write over 
  1814. the channel raises the exception notAvailable. In output mode, only output 
  1815. operations are available, `(IOChan.Flags()*(read+write) = write)' is true, and 
  1816. an attempt to read from the channel raises the exception notAvailable. All data 
  1817. written to a rewindable sequential file is appended to previous data written to 
  1818. that file. 
  1819.  
  1820.      OpenWrite - Open sequential file for writing 
  1821.      OpenAppend - Open sequential file for appending 
  1822.      OpenRead - Open sequential file for reading 
  1823.      IsSeqFile - Query whether channel is open to a sequential file 
  1824.      Reread - Rewind and select input mode 
  1825.      Rewrite - Rewind and select output mode 
  1826.      Close - Close sequential file 
  1827.  
  1828.  
  1829. ΓòÉΓòÉΓòÉ 3.4.3.1. OpenWrite - Open sequential file for writing ΓòÉΓòÉΓòÉ
  1830.  
  1831. PROCEDURE OpenWrite (VAR cid: ChanId;
  1832.                      name: ARRAY OF CHAR;
  1833.                      flags: FlagSet;
  1834.                      VAR res: OpenResults);
  1835.  
  1836. Module SeqFile 
  1837.  
  1838. If successful, the procedure OpenWrite assigns to cid the identity of a channel 
  1839. that is connected to a stored file specified by name; the value opened is 
  1840. assigned to res. Output mode is selected and the file is truncated to zero 
  1841. length. 
  1842.  
  1843. Inclusion of the write flag in the parameter flags is implied. 
  1844.  
  1845. If the call is to succeed, a destination of the given name has to not already 
  1846. exist unless the flag old is given; if the read flag is included in the 
  1847. request, the Reread operation is available. 
  1848.  
  1849. The effect of a Reset operation on the channel is to truncate the file to zero 
  1850. length and to select output mode. 
  1851.  
  1852. If a channel cannot be opened as required, the value of res indicates the 
  1853. reason, and cid identifies the invalid channel. 
  1854.  
  1855. NOTE: 
  1856.  
  1857. Distinct modes in combination with text and/or raw are given by the following 
  1858. equivalent sets of flags: 
  1859.  
  1860.      write to a new file: write 
  1861.  
  1862.      write to a new file or a truncated existing file: old write+old 
  1863.  
  1864.      write to a new file, need read operations: write+read read 
  1865.  
  1866.      write to a new or existing file, need read operations: old+read 
  1867.       write+old+read 
  1868.  
  1869.  
  1870. ΓòÉΓòÉΓòÉ 3.4.3.2. OpenAppend - Open sequential file for appending ΓòÉΓòÉΓòÉ
  1871.  
  1872. PROCEDURE OpenAppend (VAR cid: ChanId;
  1873.                       name: ARRAY OF CHAR;
  1874.                       flags: FlagSet;
  1875.                       VAR res: OpenResults);
  1876.  
  1877. Module SeqFile 
  1878.  
  1879. If successful, the procedure OpenAppend assigns to cid the identity of a 
  1880. channel that is connected to a stored file specified by name; the value opened 
  1881. is assigned to res. Output mode is selected. 
  1882.  
  1883. Have to write something here. 
  1884.  
  1885. Inclusion of the write and old flags in the parameter flags is implied; a 
  1886. destination of the given name may already exist. 
  1887.  
  1888. If the read flag is included in the request, the Reread operation is available 
  1889. if the call is to succeed. 
  1890.  
  1891. The effect of a Reset operation on the channel is to select output mode. 
  1892.  
  1893. If a channel cannot be opened as required, the value of res indicates the 
  1894. reason, and cid identifies the invalid channel. 
  1895.  
  1896. NOTE: 
  1897.  
  1898. Distinct modes in combination with text and/or raw are given by the following 
  1899. equivalent sets of flags: 
  1900.  
  1901.      write to a new or append to an existing file: write old write+old 
  1902.  
  1903.      write to a new or append to an existing file, need read operations: read 
  1904.       write+read old+read write+old+read 
  1905.  
  1906.  
  1907. ΓòÉΓòÉΓòÉ 3.4.3.3. OpenRead - Open sequential file for reading ΓòÉΓòÉΓòÉ
  1908.  
  1909. PROCEDURE OpenRead (VAR cid: ChanId;
  1910.                     name: ARRAY OF CHAR;
  1911.                     flags: FlagSet;
  1912.                     VAR res: OpenResults);
  1913.  
  1914. Module SeqFile 
  1915.  
  1916. If successful, the procedure OpenRead assigns to cid the identity of a channel 
  1917. that is connected to a stored file specified by name; the value opened is 
  1918. assigned to res. Input mode is selected and the read position correspond to the 
  1919. start of the file. 
  1920.  
  1921. Inclusion of the read and old flags in the parameter flags is implied; a 
  1922. destination of the given name has to already exist if the call is to succeed. 
  1923.  
  1924. If the write flag is included in the request, the Rewrite operation is 
  1925. available if the call is to succeed. 
  1926.  
  1927. The effect of a Reset operation on the channel is to select input mode and to 
  1928. set the read position to the start of the file. 
  1929.  
  1930. If a channel cannot be opened as required, the value of res indicates the 
  1931. reason, and cid identifies the invalid channel. 
  1932.  
  1933. NOTE: 
  1934.  
  1935. Distinct modes in combination with text and/or raw are given by the following 
  1936. equivalent sets of flags: 
  1937.  
  1938.      read from an existing file: read old read+old 
  1939.  
  1940.      read from an existing file, need write operations: write read+write 
  1941.       old+write read+old+write 
  1942.  
  1943.  
  1944. ΓòÉΓòÉΓòÉ 3.4.3.4. IsSeqFile - Query whether channel is open to a sequential file ΓòÉΓòÉΓòÉ
  1945.  
  1946. PROCEDURE IsSeqFile (cid: ChanId): BOOLEAN;
  1947.  
  1948. Module SeqFile 
  1949.  
  1950. The function procedure IsSeqFile returns TRUE if the channel identified by cid 
  1951. is open to a rewindable sequential file, and FALSE otherwise. 
  1952.  
  1953.  
  1954. ΓòÉΓòÉΓòÉ 3.4.3.5. Reread - Rewind and select input mode ΓòÉΓòÉΓòÉ
  1955.  
  1956. PROCEDURE Reread (cid: ChanId);
  1957.  
  1958. Module SeqFile 
  1959.  
  1960. If the channel identified by cid is open to a rewindable sequential file, the 
  1961. procedure Reread attempts to set the read position of the channel to the start 
  1962. of the file, and to select input mode; otherwise, the exception wrongDevice is 
  1963. raised. 
  1964.  
  1965. If the operation cannot be performed, perhaps because of insufficient 
  1966. permissions, neither input mode nor output mode are selected. 
  1967.  
  1968.  
  1969. ΓòÉΓòÉΓòÉ 3.4.3.6. Rewrite - Rewind and select output mode ΓòÉΓòÉΓòÉ
  1970.  
  1971. PROCEDURE Rewrite (cid: ChanId);
  1972.  
  1973. Module SeqFile 
  1974.  
  1975. If the channel identified by cid is open to a rewindable sequential file, the 
  1976. procedure Rewrite attempts to set the write position of the channel to the 
  1977. start of the file, to truncate the file to zero length, and to select output 
  1978. mode; otherwise, the exception wrongDevice is raised. 
  1979.  
  1980. If the operation cannot be performed, perhaps because of insufficient 
  1981. permissions, neither input mode nor output mode are selected. 
  1982.  
  1983.  
  1984. ΓòÉΓòÉΓòÉ 3.4.3.7. Close - Close sequential file ΓòÉΓòÉΓòÉ
  1985.  
  1986. PROCEDURE Close (VAR cid: ChanId);
  1987.  
  1988. Module SeqFile 
  1989.  
  1990. If the channel identified by cid is open to a rewindable sequential file, the 
  1991. procedure Close closes the channel and assigns the value identifying the 
  1992. invalid channel to cid; otherwise, the exception wrongDevice is raised. 
  1993.  
  1994.  
  1995. ΓòÉΓòÉΓòÉ 3.4.4. Module RndFile ΓòÉΓòÉΓòÉ
  1996.  
  1997. The module RndFile provides facilities for obtaining and releasing channels 
  1998. that are connected to named random access files. 
  1999.  
  2000. The types IOChan.ChanId, ChanConsts.FlagSet, and ChanConsts.OpenResults are 
  2001. re-expored. The singleton values of the type FlagSet are declared for 
  2002. convinience: 
  2003.  
  2004. TYPE
  2005.   ChanId = IOChan.ChanId;
  2006.   FlagSet = ChanConsts.FlagSet;
  2007.   OpenResults = ChanConsts.OpenResults;
  2008.  
  2009. CONST
  2010.   read = FlagSet{ChanConsts.readFlag};
  2011.     (* input operations are requested/available *)
  2012.   write = FlagSet{ChanConsts.writeFlag};
  2013.     (* output operations are requested/available *)
  2014.   old = FlagSet{ChanConsts.oldFlag};
  2015.     (* a file may/must/did exist before the channel is opened *)
  2016.   text = FlagSet{ChanConsts.textFlag};
  2017.     (* text operations are requested/available *)
  2018.   raw = FlagSet{ChanConsts.rawFlag};
  2019.     (* raw operations are requested/available *)
  2020.  
  2021. Channels opened by the module RndFile have an associated read/write position in 
  2022. the corresponding random-access file. The read/write position is at the start 
  2023. of the file after opening, or after a Reset operation on the channel. It is 
  2024. moved forward by the number of positions occupied by data that are taken from 
  2025. the file by an input operation, or written to the file by an output operation. 
  2026.  
  2027. CONST
  2028.   FilePosSize = <implementation-defined whole
  2029.                  number greater than zero>;
  2030.  
  2031. TYPE
  2032.   FilePos = ARRAY [1 .. FilePosSize] OF SYSTEM.LOC;
  2033.  
  2034. NOTE: 
  2035.  
  2036. The implementation-defined type FilePos has been specified in a way that 
  2037. enables values of this type to be read from or written to a file, while 
  2038. maintaining a degree of opacity for the type. 
  2039.  
  2040. A random-access file have a length corresponding to the position after the 
  2041. highest read/write position at which data have been written. This length is 
  2042. zero if no data have been written to the file. If the read/write position is 
  2043. set at the current length, either implicitly on an input or output operation, 
  2044. or explicitly by a positioning operation, the effect of an input operation is 
  2045. as if the input stream had ended. A write at that position, if necessary, 
  2046. attempts to allocate more physical storage for the file. 
  2047.  
  2048. In a request to open a random-access file, the flags read, write, old, text, 
  2049. and raw apply. If text is not included in the request parameter flags, 
  2050. inclusion of raw is implied. 
  2051.  
  2052.      OpenOld - Open existing random-aceess file 
  2053.      OpenClean - Open and clear random-aceess file 
  2054.      IsRndFile - Query whether channel is open to a random access file 
  2055.      IsRndFileException - Query exceptional state 
  2056.      StartPos - Query start position 
  2057.      CurrentPos - Query current position 
  2058.      EndPos - Query end position 
  2059.      NewPos - Calculate new position 
  2060.      SetPos - Set new position 
  2061.      Close - Close random access file 
  2062.  
  2063.  
  2064. ΓòÉΓòÉΓòÉ 3.4.4.1. OpenOld - Open existing random-aceess file ΓòÉΓòÉΓòÉ
  2065.  
  2066. PROCEDURE OpenOld (VAR cid: ChanId;
  2067.                    name: ARRAY OF CHAR;
  2068.                    flags: FlagSet;
  2069.                    VAR res: OpenResults);
  2070.  
  2071. Module RndFile 
  2072.  
  2073. If successful, the procedure OpenOld assigns to cid the identity of a channel 
  2074. that is connected to a random access file specified by name; the value opened 
  2075. is assigned to res. The read/write position correspond to the start of the 
  2076. file. 
  2077.  
  2078. Inclusion of the old flag in the parameter flags is implied; a file of the 
  2079. given name have to already exist if the call is to succeed. 
  2080.  
  2081. If the write flag is not included in the request, inclusion of the read flag is 
  2082. implied. 
  2083.  
  2084. If a channel cannot be opened as required, the value of res indicates the 
  2085. reason, and cid identifies the invalid channel. 
  2086.  
  2087. NOTE: 
  2088.  
  2089. Distinct modes in combination with text and/or raw are given by the following 
  2090. equivalent sets of flags: 
  2091.  
  2092.      read from an existing file: read old read+old 
  2093.  
  2094.      write to an existing file: write write+old 
  2095.  
  2096.      read/write an existing file: read+write read+write+old 
  2097.  
  2098.  
  2099. ΓòÉΓòÉΓòÉ 3.4.4.2. OpenClean - Open and clear random-aceess file ΓòÉΓòÉΓòÉ
  2100.  
  2101. PROCEDURE OpenClean (VAR cid: ChanId;
  2102.                      name: ARRAY OF CHAR;
  2103.                      flags: FlagSet;
  2104.                      VAR res: OpenResults);
  2105.  
  2106. Module RndFile 
  2107.  
  2108. If successful, the procedure OpenClean assigns to cid the identity of a channel 
  2109. that is connected to a random access file specified by name; the value opened 
  2110. is assigned to res. The file is truncated to zero length. 
  2111.  
  2112. Inclusion of the write flag in the parameter flags is implied; a destination of 
  2113. the given name has to not already exist unless the flag old is given. 
  2114.  
  2115. If a channel cannot be opened as required, the value of res indicates the 
  2116. reason, and cid identifies the invalid channel. 
  2117.  
  2118. NOTE: 
  2119.  
  2120. Distinct modes in combination with text and/or raw are given by the following 
  2121. equivalent sets of flags: 
  2122.  
  2123.      write to a new file: write 
  2124.  
  2125.      write to a new file or a truncated existing file: old write+old 
  2126.  
  2127.      write to a new file, read operations are needed: read write+read 
  2128.  
  2129.      write to a new file or a truncated existing file, read operations are 
  2130.       needed: old+read write+old+read 
  2131.  
  2132.  
  2133. ΓòÉΓòÉΓòÉ 3.4.4.3. IsRndFile - Query whether channel is open to a random access file ΓòÉΓòÉΓòÉ
  2134.  
  2135. PROCEDURE IsRndFile (cid: ChanId): BOOLEAN;
  2136.  
  2137. Module RndFile 
  2138.  
  2139. The function procedure IsRndFile returns TRUE if the channel identified by cid 
  2140. is open to a random access file, and FALSE otherwise. 
  2141.  
  2142.  
  2143. ΓòÉΓòÉΓòÉ 3.4.4.4. IsRndFileException - Query exceptional state ΓòÉΓòÉΓòÉ
  2144.  
  2145. PROCEDURE IsRndFileException (): BOOLEAN;
  2146.  
  2147. Module RndFile 
  2148.  
  2149. If the calling coroutine is in the state of exceptional execution because of 
  2150. the raising of the RndFile exception, the function procedure IsRndFileException 
  2151. returns TRUE; otherwise it returns FALSE. 
  2152.  
  2153.  
  2154. ΓòÉΓòÉΓòÉ 3.4.4.5. StartPos - Query start position ΓòÉΓòÉΓòÉ
  2155.  
  2156. PROCEDURE StartPos (cid: ChanId): FilePos;
  2157.  
  2158. Module RndFile 
  2159.  
  2160. If the channel identified by cid is open to a random access file, the function 
  2161. procedure StartPos returns the position of the start of the file; otherwise the 
  2162. exception wrongDevice is raised. 
  2163.  
  2164.  
  2165. ΓòÉΓòÉΓòÉ 3.4.4.6. CurrentPos - Query current position ΓòÉΓòÉΓòÉ
  2166.  
  2167. PROCEDURE CurrentPos (cid: ChanId): FilePos;
  2168.  
  2169. Module RndFile 
  2170.  
  2171. If the channel identified by cid is open to a random access file, the function 
  2172. procedure CurrentPos returns the current read/write position of the file; 
  2173. otherwise the exception wrongDevice is raised. 
  2174.  
  2175.  
  2176. ΓòÉΓòÉΓòÉ 3.4.4.7. EndPos - Query end position ΓòÉΓòÉΓòÉ
  2177.  
  2178. PROCEDURE EndPos (cid: ChanId): FilePos;
  2179.  
  2180. Module RndFile 
  2181.  
  2182. If the channel identified by cid is open to a random access file, the function 
  2183. procedure EndPos returns the first position in the file at or after which no 
  2184. data have been written; otherwise the exception wrongDevice is raised. 
  2185.  
  2186.  
  2187. ΓòÉΓòÉΓòÉ 3.4.4.8. NewPos - Calculate new position ΓòÉΓòÉΓòÉ
  2188.  
  2189. PROCEDURE NewPos (cid: ChanId;
  2190.                   chunks: INTEGER;
  2191.                   chunkSize: CARDINAL;
  2192.                   from: FilePos): FilePos;
  2193.  
  2194. Module RndFile 
  2195.  
  2196. If the channel identified by cid is open to a random access file, the function 
  2197. procedure NewPos returns the read/write position chunks * chunkSize places 
  2198. relative to the position in the file given by the value of from; otherwise, the 
  2199. exception wrongDevice is raised. The RndFile exception is raised if the 
  2200. required position cannot be represented as a value of the type FilePos. 
  2201.  
  2202. NOTE: 
  2203.  
  2204. Calculation of the position in a random access file at which to issue text 
  2205. operations is dependent upon knowledge of the external representation of text 
  2206. items in a particular file; the amount by which the read/write position is 
  2207. moved as a result of a text operation may vary depending upon the item that is 
  2208. read or written. For raw operations, the read/write position is always moved by 
  2209. a value equal to the storage size of variables of the type of the item read or 
  2210. written. 
  2211.  
  2212.  
  2213. ΓòÉΓòÉΓòÉ 3.4.4.9. SetPos - Set new position ΓòÉΓòÉΓòÉ
  2214.  
  2215. PROCEDURE SetPos (cid: ChanId; pos: FilePos);
  2216.  
  2217. Module RndFile 
  2218.  
  2219. If the channel identified by cid is open to a random access file, the procedure 
  2220. SetPos sets the read/write position for the file to the position given by the 
  2221. value of pos; otherwise the exception wrongDevice is raised. 
  2222.  
  2223. If the position given by the value of pos is beyond the value returned by a 
  2224. call of EndPos, `read <= IOChan.Flags()' is false, and a call of an input 
  2225. operation raises the exception notAvailable; the value of `write <= 
  2226. IOChan.Flags()' is implementation-defined and correspond to the availability of 
  2227. output operations in this case. If data are subsequently written at such a 
  2228. position, those positions that have not been written to are filled with 
  2229. implementation-defined padding values. 
  2230.  
  2231. NOTE: 
  2232.  
  2233. Setting the read/write position beyond the value returned by EndPos does not of 
  2234. itself affect the size of the file. 
  2235.  
  2236.  
  2237. ΓòÉΓòÉΓòÉ 3.4.4.10. Close - Close random access file ΓòÉΓòÉΓòÉ
  2238.  
  2239. PROCEDURE Close (VAR cid: ChanId);
  2240.  
  2241. Module RndFile 
  2242.  
  2243. If the channel identified by cid is open to a random access file, the procedure 
  2244. Close closes the channel and assign the value identifying the invalid channel 
  2245. to cid; otherwise, the exception wrongDevice is raised. 
  2246.  
  2247.  
  2248. ΓòÉΓòÉΓòÉ 3.4.5. Module TermFile ΓòÉΓòÉΓòÉ
  2249.  
  2250. The module TermFile provides facilities that allow elementary access to an 
  2251. interactive terminal. 
  2252.  
  2253. The types IOChan.ChanId, ChanConsts.FlagSet, and ChanConsts.OpenResults are 
  2254. re-expored. The singleton values of the type FlagSet are declared for 
  2255. convinience: 
  2256.  
  2257. TYPE
  2258.   ChanId = IOChan.ChanId;
  2259.   FlagSet = ChanConsts.FlagSet;
  2260.   OpenResults = ChanConsts.OpenResults;
  2261.  
  2262. CONST
  2263.   read = FlagSet{ChanConsts.readFlag};
  2264.     (* input operations are requested/available *)
  2265.   write = FlagSet{ChanConsts.writeFlag};
  2266.     (* output operations are requested/available *)
  2267.   text = FlagSet{ChanConsts.textFlag};
  2268.     (* text operations are requested/available *)
  2269.   raw = FlagSet{ChanConsts.rawFlag};
  2270.     (* raw operations are requested/available *)
  2271.   echo = FlagSet{ChanConsts.echoFlag};
  2272.     (* echoing by interactive device on reading of
  2273.        characters from input stream requested/applies *)
  2274.  
  2275. Channels connected to the terminal device are opened in line mode or in 
  2276. single-character mode. In line mode, items are echoed before being added to the 
  2277. input stream and are added a line at a time. In single character mode, items 
  2278. are added to the input stream as they are typed, and are echoed as they are 
  2279. removed from the input stream by a text read device operation, provided they 
  2280. have not already been echoed. 
  2281.  
  2282. Typed characters are distributed between multiple channels according to the 
  2283. sequence of read requests. 
  2284.  
  2285. NOTE: 
  2286.  
  2287. If all the channels open to the terminal are open in line mode, the terminal 
  2288. device operates exclusively in line mode; in that case, echoing might be 
  2289. performed by an underlying operating system. Similarly, if all the channels 
  2290. open to the terminal are open in single-character mode, the terminal device 
  2291. operates exclusively in single-character mode; in that case, echoing only 
  2292. occurs on reading from a channel and not on looking or skipping: this allows 
  2293. interactive input routines to suppress the echoing of unwanted or unexpected 
  2294. characters. 
  2295.  
  2296. If an implementation allows it, there might be one or more channels open in 
  2297. line mode, and one or more channels open in single-character mode. In that 
  2298. case, echoing is postponed until the treatment of characters can be determined 
  2299. according to the sequence of calls of input operations. This behaviour allows 
  2300. programs that use the terminal in different modes to be written in a modular 
  2301. fashion, there being no need explicitly to save and restore the state of the 
  2302. terminal device. 
  2303.  
  2304. In a request to open a channel to the terminal device, the flags read, write, 
  2305. text, raw, and echo apply. If raw is not included in the request parameter 
  2306. flags, inclusion of text is implied. If the read flag is not included in the 
  2307. request, inclusion of the write flag is implied. 
  2308.  
  2309.      Open - Open terminal 
  2310.      IsTermFile - Query whether channel is opened to terminal 
  2311.      Close - Close terminal 
  2312.  
  2313.  
  2314. ΓòÉΓòÉΓòÉ 3.4.5.1. Open - Open terminal ΓòÉΓòÉΓòÉ
  2315.  
  2316. PROCEDURE Open (VAR cid: ChanId;
  2317.                 flags: FlagSet;
  2318.                 VAR res: OpenResults);
  2319.  
  2320. Module TermFile 
  2321.  
  2322. If successful, the procedure Open assigns to cid the identity of a channel that 
  2323. is connected to the terminal device. 
  2324.  
  2325. If the echo flag is included in the request, single-character mode is available 
  2326. if the call is to succeed and the channel operates in single-character mode. 
  2327. Without the echo flag, line mode is available if the call is to succeed and the 
  2328. channel operates in line mode. 
  2329.  
  2330. If a channel cannot be opened as required, the value of res indicates the 
  2331. reason, and cid identifies the invalid channel. 
  2332.  
  2333.  
  2334. ΓòÉΓòÉΓòÉ 3.4.5.2. IsTermFile - Query whether channel is opened to terminal ΓòÉΓòÉΓòÉ
  2335.  
  2336. PROCEDURE IsTermFile (cid: ChanId): BOOLEAN;
  2337.  
  2338. Module TermFile 
  2339.  
  2340. The function procedure IsTermFile returns TRUE if the channel identified by cid 
  2341. is open to the terminal device, and FALSE otherwise. 
  2342.  
  2343.  
  2344. ΓòÉΓòÉΓòÉ 3.4.5.3. Close - Close terminal ΓòÉΓòÉΓòÉ
  2345.  
  2346. PROCEDURE Close (VAR cid: ChanId);
  2347.  
  2348. Module TermFile 
  2349.  
  2350. If the channel identified by cid is open to the terminal device, the procedure 
  2351. Close closes the channel and assigns the value identifying the invalid channel 
  2352. to cid; otherwise, the exception wrongDevice is raised. 
  2353.  
  2354.  
  2355. ΓòÉΓòÉΓòÉ 3.4.6. Module ProgramArgs ΓòÉΓòÉΓòÉ
  2356.  
  2357. The module ProgramArgs provides a channel from which input can be taken from 
  2358. any arguments given to the program. 
  2359.  
  2360. TYPE
  2361.   ChanId = IOChan.ChanId;
  2362.  
  2363. The initialization of the module ProgramArgs opens the channel from which the 
  2364. implementation-defined program arguments may be read. 
  2365.  
  2366.      ArgChan - Get program arguments channel id 
  2367.      IsArgPresent - Query whether an argument is present 
  2368.      NextArg - Skip to next argument 
  2369.  
  2370.  
  2371. ΓòÉΓòÉΓòÉ 3.4.6.1. ArgChan - Get program arguments channel id ΓòÉΓòÉΓòÉ
  2372.  
  2373. PROCEDURE ArgChan (): ChanId;
  2374.  
  2375. Module ProgramArgs 
  2376.  
  2377. The function procedure ArgChan returns a value identifying a channel from which 
  2378. the implementation-defined program arguments may be read. 
  2379.  
  2380.  
  2381. ΓòÉΓòÉΓòÉ 3.4.6.2. IsArgPresent - Query whether an argument is present ΓòÉΓòÉΓòÉ
  2382.  
  2383. PROCEDURE IsArgPresent (): BOOLEAN;
  2384.  
  2385. Module ProgramArgs 
  2386.  
  2387. The function procedure IsArgPresent returns TRUE if there is a current argument 
  2388. from which to read, and FALSE otherwise. 
  2389.  
  2390. If there is no current argument, `read <= IOChan.Flags()' is false, and 
  2391. attempting to read from the argument channel raises the exception notAvailable. 
  2392.  
  2393.  
  2394. ΓòÉΓòÉΓòÉ 3.4.6.3. NextArg - Skip to next argument ΓòÉΓòÉΓòÉ
  2395.  
  2396. PROCEDURE NextArg ();
  2397.  
  2398. Module ProgramArgs 
  2399.  
  2400. After the call to the procedure NextArg, if there is another argument, 
  2401. subsequent input from the argument channel is taken from the start of that 
  2402. argument; otherwise a call of IsArgPresent returns FALSE. 
  2403.  
  2404. NOTE: 
  2405.  
  2406. Provision of NextArg allows the treatment of arguments that contain spaces or 
  2407. line marks. 
  2408.  
  2409.  
  2410. ΓòÉΓòÉΓòÉ 3.5. Interface to Channels for New Device Modules ΓòÉΓòÉΓòÉ
  2411.  
  2412. Additional device modules may be provided to allow the library to be used with 
  2413. other input sources and output destinations. These might include, for example, 
  2414. files opened with host-specific options or parameters or with host-specific 
  2415. behaviour, a windowing system, or a speech output device. 
  2416.  
  2417.      Module IOLink 
  2418.  
  2419.  
  2420. ΓòÉΓòÉΓòÉ 3.5.1. Module IOLink ΓòÉΓòÉΓòÉ
  2421.  
  2422. The module IOLink provides facilities that allow a user to provide specialized 
  2423. device modules for use with channels, following the pattern of the rest of the 
  2424. library. 
  2425.  
  2426. A device needs to identify itself in order to allow a check to be made that 
  2427. device-dependent operations are applied only for channels opened to that 
  2428. device. To this end, values of the hidden type DeviceId are used to identify 
  2429. new device modules, and are normally obtained by them during their 
  2430. initialization by a call to the procedure AllocateDeviceId. 
  2431.  
  2432. TYPE
  2433.   DeviceId;
  2434.  
  2435. A device module procedure provided for opening a channel can obtain a new 
  2436. channel by calling the procedure MakeChan. If a channel is allocated, but the 
  2437. call of the device module open procedure is not successful for some reason, the 
  2438. device module should release the channel by calling the procedure UnMakeChan, 
  2439. and return the value identifying the invalid channel to its client. 
  2440.  
  2441. A call to UnMakeChan is also made on a successful call of a device module 
  2442. procedure provided for closing a channel. 
  2443.  
  2444. If a call of a device module `open' procedure is successful, then by calling 
  2445. the function procedure DeviceTablePtrValue, a device module can obtain a 
  2446. pointer (of the type DeviceTablePtr) to a `device table' (of a record type 
  2447. DeviceTable) for the channel. The fields of this record are initialized by 
  2448. MakeChan, but the procedure can then change any fields of the device table 
  2449. needed to install its own values for the device data, supported operations, and 
  2450. flags. 
  2451.  
  2452. Device tables have: 
  2453.  
  2454.    1. a field in which the device module can store private data, 
  2455.  
  2456.    2. a field in which the value identifying the device module is stored, 
  2457.  
  2458.    3. a field in which the value identifying the channel is stored, 
  2459.  
  2460.    4. a field in which the read result is stored, 
  2461.  
  2462.    5. a field in which device error numbers are stored prior to the raising of 
  2463.       a device error exception, 
  2464.  
  2465.    6. a field in which flags are stored indicating those which apply, 
  2466.  
  2467.    7. a field for each device procedure. 
  2468.  
  2469.  (The fields are initialized by MakeChan to the values shown in the definition 
  2470.  module below.) 
  2471.  
  2472.  By calling the function procedure IsDevice, a device module can enquire 
  2473.  whether it was responsible for opening a given channel. This allows it to 
  2474.  implement a corresponding enquiry function that is exported from the device 
  2475.  module itself. 
  2476.  
  2477.  Client modules may raise appropriate exceptions; to support this facility, the 
  2478.  type DevExceptionRange and the procedure RAISEdevException can be used. 
  2479.  
  2480.   TYPE
  2481.     DeviceTablePtr = POINTER TO DeviceTable;
  2482.       (* Values of this type are used to refer to device tables *)
  2483.  
  2484.   TYPE
  2485.     LookProc      = PROCEDURE (DeviceTablePtr,
  2486.                                VAR CHAR,
  2487.                                VAR IOConsts.ReadResults);
  2488.     SkipProc      = PROCEDURE (DeviceTablePtr);
  2489.     SkipLookProc  = PROCEDURE (DeviceTablePtr,
  2490.                                VAR CHAR,
  2491.                                VAR IOConsts.ReadResults);
  2492.     WriteLnProc   = PROCEDURE (DeviceTablePtr);
  2493.     TextReadProc  = PROCEDURE (DeviceTablePtr,
  2494.                                SYSTEM.ADDRESS,
  2495.                                CARDINAL,
  2496.                                VAR CARDINAL);
  2497.     TextWriteProc = PROCEDURE (DeviceTablePtr,
  2498.                                SYSTEM.ADDRESS,
  2499.                                CARDINAL);
  2500.     RawReadProc   = PROCEDURE (DeviceTablePtr,
  2501.                                SYSTEM.ADDRESS,
  2502.                                CARDINAL,
  2503.                                VAR CARDINAL);
  2504.     RawWriteProc  = PROCEDURE (DeviceTablePtr,
  2505.                                SYSTEM.ADDRESS,
  2506.                                CARDINAL);
  2507.     GetNameProc   = PROCEDURE (DeviceTablePtr,
  2508.                                VAR ARRAY OF CHAR);
  2509.     ResetProc     = PROCEDURE (DeviceTablePtr);
  2510.     FlushProc     = PROCEDURE (DeviceTablePtr);
  2511.     FreeProc      = PROCEDURE (DeviceTablePtr);
  2512.       (* Carry out the operations involved in closing
  2513.          the corresponding channel, including flushing buffers,
  2514.          but do not unmake the channel.
  2515.       *)
  2516.  
  2517.   TYPE
  2518.     DeviceData = SYSTEM.ADDRESS;
  2519.  
  2520.   DeviceTable =
  2521.     RECORD           (* Initialized by MakeChan to: *)
  2522.       cd:          DeviceData;
  2523.                      (* the value NIL *)
  2524.       did:         DeviceId;
  2525.                      (* the value given in the call of MakeChan *)
  2526.       cid:         IOChan.ChanId;
  2527.                      (* the identity of the channel *)
  2528.       result:      IOConsts.ReadResults;
  2529.                      (* the value notKnown *)
  2530.       errNum:      IOChan.DeviceErrNum;
  2531.                      (* undefined *)
  2532.       flags:       ChanConsts.FlagSet;
  2533.                      (* ChanConsts.FlagSet{} *)
  2534.       doLook:      LookProc;
  2535.                      (* raise exception notAvailable *)
  2536.       doSkip:      SkipProc;
  2537.                      (* raise exception notAvailable *)
  2538.       doSkipLook:  SkipLookProc;
  2539.                      (* raise exception notAvailable *)
  2540.       doLnWrite:   WriteLnProc;
  2541.                      (* raise exception notAvailable *)
  2542.       doTextRead:  TextReadProc;
  2543.                      (* raise exception notAvailable *)
  2544.       doTextWrite: TextWriteProc;
  2545.                      (* raise exception notAvailable *)
  2546.       doRawRead:   RawReadProc;
  2547.                      (* raise exception notAvailable *)
  2548.       doRawWrite:  RawWriteProc;
  2549.                      (* raise exception notAvailable *)
  2550.       doGetName:   GetNameProc;
  2551.                      (* return the empty string *)
  2552.       doReset:     ResetProc;
  2553.                      (* do nothing *)
  2554.       doFlush:     FlushProc;
  2555.                      (* do nothing *)
  2556.       doFree:      FreeProc;
  2557.                      (* do nothing *)
  2558.     END;
  2559.  
  2560.   TYPE
  2561.     DevExceptionRange = [IOChan.notAvailable .. IOChan.textParseError];
  2562.  
  2563.      AllocateDeviceId - Allocate device id 
  2564.      MakeChan - Allocate a new channel for device 
  2565.      UnMakeChan - Deallocate channel from device 
  2566.      DeviceTablePtrValue - Get device table for channel 
  2567.      IsDevice - Query channel's device 
  2568.      RAISEdevException - Raise device exception 
  2569.      IsIOException - Query exceptional state 
  2570.      IOException - Query exception id 
  2571.  
  2572.  
  2573. ΓòÉΓòÉΓòÉ 3.5.1.1. AllocateDeviceId - Allocate device id ΓòÉΓòÉΓòÉ
  2574.  
  2575. PROCEDURE AllocateDeviceId (VAR did: DeviceId);
  2576.  
  2577. Module IOLink 
  2578.  
  2579. The procedure AllocateDeviceId allocates an unique value of the type DeviceId, 
  2580. and assign this value to did. 
  2581.  
  2582.  
  2583. ΓòÉΓòÉΓòÉ 3.5.1.2. MakeChan - Allocate a new channel for device ΓòÉΓòÉΓòÉ
  2584.  
  2585. PROCEDURE MakeChan (did: DeviceId;
  2586.                     VAR cid: IOChan.ChanId);
  2587.  
  2588. Module IOLink 
  2589.  
  2590. The procedure MakeChan attempts to allocate a new channel for the device module 
  2591. identified by did. If no more channels can be allocated, the value identifying 
  2592. the invalid channel is assigned to cid. Otherwise, a value identifying a new 
  2593. initialized channel is assigned to cid. 
  2594.  
  2595.  
  2596. ΓòÉΓòÉΓòÉ 3.5.1.3. UnMakeChan - Deallocate channel from device ΓòÉΓòÉΓòÉ
  2597.  
  2598. PROCEDURE UnMakeChan (did: DeviceId;
  2599.                       VAR cid: IOChan.ChanId);
  2600.  
  2601. Module IOLink 
  2602.  
  2603. Provided the device module identified by did is the module that made the 
  2604. channel identified by cid, the procedure UnMakeChan deallocates the channel 
  2605. identified by cid, and assigns the value identifying the invalid channel to 
  2606. cid; otherwise the exception wrongDevice is raised. 
  2607.  
  2608.  
  2609. ΓòÉΓòÉΓòÉ 3.5.1.4. DeviceTablePtrValue - Get device table for channel ΓòÉΓòÉΓòÉ
  2610.  
  2611. PROCEDURE DeviceTablePtrValue (cid: IOChan.ChanId;
  2612.                                did: DeviceId
  2613.                               ): DeviceTablePtr;
  2614.  
  2615. Module IOLink 
  2616.  
  2617. Provided that the device module identified by did is the module that made the 
  2618. channel identified by cid, the function procedure DeviceTablePtrValue returns a 
  2619. pointer to the device table for the channel identified by cid; otherwise the 
  2620. exception wrongDevice is raised. 
  2621.  
  2622.  
  2623. ΓòÉΓòÉΓòÉ 3.5.1.5. IsDevice - Query channel's device ΓòÉΓòÉΓòÉ
  2624.  
  2625. PROCEDURE IsDevice (cid: IOChan.ChanId;
  2626.                     did: DeviceId
  2627.                    ): BOOLEAN;
  2628.  
  2629. Module IOLink 
  2630.  
  2631. The function procedure IsDevice returns TRUE if the device module identified by 
  2632. did is the module that made the channel identified by cid, and otherwise 
  2633. returns FALSE. 
  2634.  
  2635.  
  2636. ΓòÉΓòÉΓòÉ 3.5.1.6. RAISEdevException - Raise device exception ΓòÉΓòÉΓòÉ
  2637.  
  2638. PROCEDURE RAISEdevException (cid: IOChan.ChanId;
  2639.                              did: DeviceId;
  2640.                              x: DevExceptionRange;
  2641.                              s: ARRAY OF CHAR);
  2642.  
  2643. Module IOLink 
  2644.  
  2645. Provided that the device module identified by did is the module that made the 
  2646. channel identified by cid, the procedure RAISEdevException raises the exception 
  2647. given by x, and includes the string value in s in the exception message; 
  2648. otherwise the exception wrongDevice is raised. 
  2649.  
  2650.  
  2651. ΓòÉΓòÉΓòÉ 3.5.1.7. IsIOException - Query exceptional state ΓòÉΓòÉΓòÉ
  2652.  
  2653. PROCEDURE IsIOException (): BOOLEAN;
  2654.  
  2655. Module IOLink 
  2656.  
  2657. If the calling coroutine is in the state of exceptional execution because of 
  2658. the raising of an exception from IOChan.ChanExceptions, the function procedure 
  2659. IsIOException returns TRUE; otherwise it returns FALSE. 
  2660.  
  2661.  
  2662. ΓòÉΓòÉΓòÉ 3.5.1.8. IOException - Query exception id ΓòÉΓòÉΓòÉ
  2663.  
  2664. PROCEDURE IOException (): IOChan.ChanExceptions;
  2665.  
  2666. Module IOLink 
  2667.  
  2668. If the calling coroutine is in the state of exceptional execution because of 
  2669. the raising of an exception from IOChan.ChanExceptions, the function procedure 
  2670. IOException returns the value that identifies the raised exception; otherwise 
  2671. the language exception exException is raised. 
  2672.  
  2673. NOTE: 
  2674.  
  2675. A single value of EXCEPTIONS.ExceptionSource is used to identify the source of 
  2676. input/output library exceptions corresponding to IOChan.ChanExceptions. The 
  2677. procedures IsIOException and IOException are included so that this value need 
  2678. not be exported for corresponding procedures to be provided through the IOChan 
  2679. interface. 
  2680.  
  2681.  
  2682. ΓòÉΓòÉΓòÉ 4. Mathematical ΓòÉΓòÉΓòÉ
  2683.  
  2684. The mathematical libraries provide the common mathematical functions and some 
  2685. constants. 
  2686.  
  2687. The module RealMath provides the constants and functions for the type REAL, 
  2688. while the module LongMath provides similar constants and functions for the type 
  2689. LONGREAL. 
  2690.  
  2691. The module ComplexMath provides the constants and functions for the type 
  2692. COMPLEX, while the module LongComplexMath provides similar functions for the 
  2693. type LONGCOMPLEX. 
  2694.  
  2695.      Modules RealMath and LongMath 
  2696.      Modules ComplexMath and LongComplexMath 
  2697.  
  2698.  
  2699. ΓòÉΓòÉΓòÉ 4.1. Modules RealMath and LongMath ΓòÉΓòÉΓòÉ
  2700.  
  2701. The semantics of the two modules is the same, except that where the module 
  2702. RealMath refers to the pervasive type REAL, the corresponding function in 
  2703. LongMath refers to the pervasive type LONGREAL. 
  2704.  
  2705. NOTE: 
  2706.  
  2707. The above statement is merely to avoid needless repetition of the semantics for 
  2708. LongMath. 
  2709.  
  2710. The units used for angular quantities are radians. 
  2711.  
  2712.      Constants - Useful constants 
  2713.      sqrt - Calculate square root 
  2714.      exp - Calculate exponent 
  2715.      ln - Calculate natural logarithm 
  2716.      sin - Calculate sine 
  2717.      cos - Calculate cosine 
  2718.      tan - Calculate tangent 
  2719.      arcsin - Calculate arcsine 
  2720.      arccos - Calculate arccosine 
  2721.      arctan - Calculate arctangent 
  2722.      power - Calculate power 
  2723.      round - Round 
  2724.      IsRMathException - Query exceptional state 
  2725.  
  2726.  
  2727. ΓòÉΓòÉΓòÉ 4.1.1. Constants - Useful constants ΓòÉΓòÉΓòÉ
  2728.  
  2729. CONST
  2730.   pi   = 3.1415926535897932384626433832795028841972;
  2731.   exp1 = 2.7182818284590452353602874713526624977572;
  2732.  
  2733. Modules: RealMath, LongMath 
  2734.  
  2735. The constant pi provides an implementation-defined approximation to the 
  2736. mathematical constant Γòò. The constant exp1 provides an implementation-defined 
  2737. approximation to the mathematical constant e. 
  2738.  
  2739. NOTE: 
  2740.  
  2741. Due to the approximations involved, sin(pi) might not equal zero exactly; 
  2742. similarly, exp1 might not equal exp(1) exactly. 
  2743.  
  2744.  
  2745. ΓòÉΓòÉΓòÉ 4.1.2. sqrt - Calculate square root ΓòÉΓòÉΓòÉ
  2746.  
  2747. PROCEDURE sqrt (x: REAL): REAL;
  2748. PROCEDURE sqrt (x: LONGREAL): LONGREAL;
  2749.  
  2750. Modules: RealMath, LongMath 
  2751.  
  2752. The function procedure sqrt returns an implementation-defined approximation to 
  2753. the positive signed square root of x. An exception is raised if x is negative. 
  2754.  
  2755.  
  2756. ΓòÉΓòÉΓòÉ 4.1.3. exp - Calculate exponent ΓòÉΓòÉΓòÉ
  2757.  
  2758. PROCEDURE exp (x: REAL): REAL;
  2759. PROCEDURE exp (x: LONGREAL): LONGREAL;
  2760.  
  2761. Modules: RealMath, LongMath 
  2762.  
  2763. The function procedure exp returns an implementation-defined approximation to 
  2764. the mathematical constant e raised to the power of x. 
  2765.  
  2766.  
  2767. ΓòÉΓòÉΓòÉ 4.1.4. ln - Calculate natural logarithm ΓòÉΓòÉΓòÉ
  2768.  
  2769. PROCEDURE ln (x: REAL): REAL;
  2770. PROCEDURE ln (x: LONGREAL): LONGREAL;
  2771.  
  2772. Modules: RealMath, LongMath 
  2773.  
  2774. The function procedure ln returns an implementation-defined approximation to 
  2775. the natural logarithm of x. An exception is raised if x is zero or negative. 
  2776.  
  2777.  
  2778. ΓòÉΓòÉΓòÉ 4.1.5. sin - Calculate sine ΓòÉΓòÉΓòÉ
  2779.  
  2780. PROCEDURE sin (x: REAL): REAL;
  2781. PROCEDURE sin (x: LONGREAL): LONGREAL;
  2782.  
  2783. Modules: RealMath, LongMath 
  2784.  
  2785. The function procedure sin returns an implementation-defined approximation to 
  2786. the sine of x. 
  2787.  
  2788.  
  2789. ΓòÉΓòÉΓòÉ 4.1.6. cos - Calculate cosine ΓòÉΓòÉΓòÉ
  2790.  
  2791. PROCEDURE cos (x: REAL): REAL;
  2792. PROCEDURE cos (x: LONGREAL): LONGREAL;
  2793.  
  2794. Modules: RealMath, LongMath 
  2795.  
  2796. The function procedure cos returns an implementation-defined approximation to 
  2797. the cosine of x. 
  2798.  
  2799.  
  2800. ΓòÉΓòÉΓòÉ 4.1.7. tan - Calculate tangent ΓòÉΓòÉΓòÉ
  2801.  
  2802. PROCEDURE tan (x: REAL): REAL;
  2803. PROCEDURE tan (x: LONGREAL): LONGREAL;
  2804.  
  2805. Modules: RealMath, LongMath 
  2806.  
  2807. The function procedure tan returns an implementation-defined approximation to 
  2808. the tangent of x. An exception is raised if x is an odd multiple of Γòò/2. 
  2809.  
  2810.  
  2811. ΓòÉΓòÉΓòÉ 4.1.8. arcsin - Calculate arcsine ΓòÉΓòÉΓòÉ
  2812.  
  2813. PROCEDURE arcsin (x: REAL): REAL;
  2814. PROCEDURE arcsin (x: LONGREAL): LONGREAL;
  2815.  
  2816. Modules: RealMath, LongMath 
  2817.  
  2818. The function procedure arcsin returns an implementation-defined approximation 
  2819. to the arcsine of x. An exception is raised if the absolute value of x is 
  2820. greater than one. 
  2821.  
  2822.  
  2823. ΓòÉΓòÉΓòÉ 4.1.9. arccos - Calculate arccosine ΓòÉΓòÉΓòÉ
  2824.  
  2825. PROCEDURE arccos (x: REAL): REAL;
  2826. PROCEDURE arccos (x: LONGREAL): LONGREAL;
  2827.  
  2828. Modules: RealMath, LongMath 
  2829.  
  2830. The function procedure arccos returns an implementation-defined approximation 
  2831. to the arccosine of x. An exception is raised if the absolute value of x is 
  2832. greater than one. 
  2833.  
  2834.  
  2835. ΓòÉΓòÉΓòÉ 4.1.10. arctan - Calculate arctangent ΓòÉΓòÉΓòÉ
  2836.  
  2837. PROCEDURE arctan (x: REAL): REAL;
  2838. PROCEDURE arctan (x: LONGREAL): LONGREAL;
  2839.  
  2840. Modules: RealMath, LongMath 
  2841.  
  2842. The function procedure arctan returns an implementation-defined approximation 
  2843. to the arctangent of x. 
  2844.  
  2845.  
  2846. ΓòÉΓòÉΓòÉ 4.1.11. power - Calculate power ΓòÉΓòÉΓòÉ
  2847.  
  2848. PROCEDURE power (base, exponent: REAL): REAL;
  2849. PROCEDURE power (base, exponent: LONGREAL): LONGREAL;
  2850.  
  2851. Modules: RealMath, LongMath 
  2852.  
  2853. The function procedure power returns an implementation-defined approximation to 
  2854. the result obtained by raising base to the power of exponent. An exception is 
  2855. raised if the value of base is zero or negative. 
  2856.  
  2857. This function is mathematically equivalent to ?(y ?(x)) but may be computed 
  2858. differently. 
  2859.  
  2860.  
  2861. ΓòÉΓòÉΓòÉ 4.1.12. round - Round ΓòÉΓòÉΓòÉ
  2862.  
  2863. PROCEDURE round (x: REAL): INTEGER;
  2864. PROCEDURE round (x: LONGREAL): INTEGER;
  2865.  
  2866. Modules: RealMath, LongMath 
  2867.  
  2868. The function procedure round returns the nearest integer to the value of x. The 
  2869. result is an implementation-defined selection of the two possible values if the 
  2870. value of x is midway between two integer values. An exception occurs and may be 
  2871. raised if the mathematical result is not within the range of the type INTEGER. 
  2872.  
  2873.  
  2874. ΓòÉΓòÉΓòÉ 4.1.13. IsRMathException - Query exceptional state ΓòÉΓòÉΓòÉ
  2875.  
  2876. PROCEDURE IsRMathException (): BOOLEAN;
  2877. PROCEDURE IsRMathException (): BOOLEAN;
  2878.  
  2879. Modules: RealMath, LongMath 
  2880.  
  2881. If the calling coroutine is in the state of exceptional execution because of 
  2882. the raising of the RealMath exception, the function procedure 
  2883. RealMath.IsRMathException returns TRUE; otherwise the value is FALSE. 
  2884.  
  2885. If the calling coroutine is in the state of exceptional execution because of 
  2886. the raising of the LongMath exception, the function procedure 
  2887. LongMath.IsRMathException returns TRUE; otherwise the value is FALSE. 
  2888.  
  2889.  
  2890. ΓòÉΓòÉΓòÉ 4.2. Modules ComplexMath and LongComplexMath ΓòÉΓòÉΓòÉ
  2891.  
  2892. The semantics of the two modules are the same, except that where the module 
  2893. ComplexMath refers to the pervasive type COMPLEX, the corresponding function in 
  2894. LongComplexMath refers to the pervasive type LONGCOMPLEX. 
  2895.  
  2896. NOTE: 
  2897.  
  2898. The above statement is merely to avoid needless repetition of the semantics for 
  2899. LongComplexMath. 
  2900.  
  2901.      Constants - Useful constants 
  2902.      abs - Calculate modulus 
  2903.      arg - Calculate argument 
  2904.      conj - Calculate conjugate 
  2905.      power - Calculate power 
  2906.      sqrt - Calculate square root 
  2907.      exp - Calculate exponent 
  2908.      ln - Calculate natural logarithm 
  2909.      sin - Calculate sine 
  2910.      cos - Calculate cosine 
  2911.      tan - Calculate tangent 
  2912.      arcsin - Calculate arcsine 
  2913.      arccos - Calculate arccosine 
  2914.      arctan - Calculate arctangent 
  2915.      polarToComplex - Convert from polar to complex 
  2916.      scalarMult - Scalar Multiplication 
  2917.      IsCMathException - Query exceptional state 
  2918.  
  2919.  
  2920. ΓòÉΓòÉΓòÉ 4.2.1. Constants - Useful constants ΓòÉΓòÉΓòÉ
  2921.  
  2922. CONST
  2923.   i = CMPLX (0.0, 1.0);
  2924.   one = CMPLX (1.0, 0.0);
  2925.   zero = CMPLX (0.0, 0.0);
  2926.  
  2927. Modules: ComplexMath, LongComplexMath 
  2928.  
  2929. The constants i, one, and zero are the implementation-defined approximations to 
  2930. the specified values. 
  2931.  
  2932. NOTE: 
  2933.  
  2934. These constants are provided for convenience. 
  2935.  
  2936.  
  2937. ΓòÉΓòÉΓòÉ 4.2.2. abs - Calculate modulus ΓòÉΓòÉΓòÉ
  2938.  
  2939. PROCEDURE abs (z: COMPLEX): REAL;
  2940. PROCEDURE abs (z: LONGCOMPLEX): LONGREAL;
  2941.  
  2942. Modules: ComplexMath, LongComplexMath 
  2943.  
  2944. The function procedure abs returns an implementation-defined approximation to 
  2945. the modulus (otherwise known as the length, or absolute value) of z. 
  2946.  
  2947. NOTE: 
  2948.  
  2949. An overflow exception may be raised in this computation, even when the complex 
  2950. number is itself well defined. 
  2951.  
  2952.  
  2953. ΓòÉΓòÉΓòÉ 4.2.3. arg - Calculate argument ΓòÉΓòÉΓòÉ
  2954.  
  2955. PROCEDURE arg (z: COMPLEX): REAL;
  2956. PROCEDURE arg (z: LONGCOMPLEX): LONGREAL;
  2957.  
  2958. Modules: ComplexMath, LongComplexMath 
  2959.  
  2960. The function procedure arg returns an implementation-defined approximation to 
  2961. the angle that z subtends to the positive real axis in the complex plane. An 
  2962. exception is raised if the modulus of z is zero. 
  2963.  
  2964.  
  2965. ΓòÉΓòÉΓòÉ 4.2.4. conj - Calculate conjugate ΓòÉΓòÉΓòÉ
  2966.  
  2967. PROCEDURE conj (z: COMPLEX): COMPLEX;
  2968. PROCEDURE conj (z: LONGCOMPLEX): LONGCOMPLEX;
  2969.  
  2970. Modules: ComplexMath, LongComplexMath 
  2971.  
  2972. The function procedure conj returns an implementation-defined approximation to 
  2973. the complex conjugate of z. 
  2974.  
  2975.  
  2976. ΓòÉΓòÉΓòÉ 4.2.5. power - Calculate power ΓòÉΓòÉΓòÉ
  2977.  
  2978. PROCEDURE power (base: COMPLEX;
  2979.                  exponent: REAL
  2980.                 ): COMPLEX;
  2981. PROCEDURE power (base: LONGCOMPLEX;
  2982.                  exponent: LONGREAL
  2983.                 ): LONGCOMPLEX;
  2984.  
  2985. Modules: ComplexMath, LongComplexMath 
  2986.  
  2987. The function procedure power returns an implementation-defined approximation to 
  2988. the result obtained by raising base to the power of exponent. 
  2989.  
  2990.  
  2991. ΓòÉΓòÉΓòÉ 4.2.6. sqrt - Calculate square root ΓòÉΓòÉΓòÉ
  2992.  
  2993. PROCEDURE sqrt (z: COMPLEX): COMPLEX;
  2994. PROCEDURE sqrt (z: LONGCOMPLEX): LONGCOMPLEX;
  2995.  
  2996. Modules: ComplexMath, LongComplexMath 
  2997.  
  2998. The function procedure sqrt returns an implementation-defined approximation to 
  2999. the principal square root of z. 
  3000.  
  3001. NOTE: 
  3002.  
  3003. That is, the result is the complex number with an argument of half the value of 
  3004. the argument of z, and whose modulus has the value of the positive square root 
  3005. of the modulus of z. 
  3006.  
  3007.  
  3008. ΓòÉΓòÉΓòÉ 4.2.7. exp - Calculate exponent ΓòÉΓòÉΓòÉ
  3009.  
  3010. PROCEDURE exp (z: COMPLEX): COMPLEX;
  3011. PROCEDURE exp (z: LONGCOMPLEX): LONGCOMPLEX;
  3012.  
  3013. Modules: ComplexMath, LongComplexMath 
  3014.  
  3015. The function procedure exp returns an implementation-defined approximation to 
  3016. the mathematical constant e raised to the power of z. 
  3017.  
  3018.  
  3019. ΓòÉΓòÉΓòÉ 4.2.8. ln - Calculate natural logarithm ΓòÉΓòÉΓòÉ
  3020.  
  3021. PROCEDURE ln (z: COMPLEX): COMPLEX;
  3022. PROCEDURE ln (z: LONGCOMPLEX): LONGCOMPLEX;
  3023.  
  3024. Modules: ComplexMath, LongComplexMath 
  3025.  
  3026. The function procedure ln returns an implementation-defined approximation to 
  3027. the principal value of the natural logarithm of z. 
  3028.  
  3029.  
  3030. ΓòÉΓòÉΓòÉ 4.2.9. sin - Calculate sine ΓòÉΓòÉΓòÉ
  3031.  
  3032. PROCEDURE sin (z: COMPLEX): COMPLEX;
  3033. PROCEDURE sin (z: LONGCOMPLEX): LONGCOMPLEX;
  3034.  
  3035. Modules: ComplexMath, LongComplexMath 
  3036.  
  3037. The function procedure sin returns an implementation-defined approximation to 
  3038. the complex sine of z. 
  3039.  
  3040.  
  3041. ΓòÉΓòÉΓòÉ 4.2.10. cos - Calculate cosine ΓòÉΓòÉΓòÉ
  3042.  
  3043. PROCEDURE cos (z: COMPLEX): COMPLEX;
  3044. PROCEDURE cos (z: LONGCOMPLEX): LONGCOMPLEX;
  3045.  
  3046. Modules: ComplexMath, LongComplexMath 
  3047.  
  3048. The function procedure cos returns an implementation-defined approximation to 
  3049. the complex cosine of z. 
  3050.  
  3051.  
  3052. ΓòÉΓòÉΓòÉ 4.2.11. tan - Calculate tangent ΓòÉΓòÉΓòÉ
  3053.  
  3054. PROCEDURE tan (z: COMPLEX): COMPLEX;
  3055. PROCEDURE tan (z: LONGCOMPLEX): LONGCOMPLEX;
  3056.  
  3057. Modules: ComplexMath, LongComplexMath 
  3058.  
  3059. The function procedure tan returns an implementation-defined approximation to 
  3060. the complex tangent of z. An exception is raised if z is an odd multiple of 
  3061. Γòò/2. 
  3062.  
  3063.  
  3064. ΓòÉΓòÉΓòÉ 4.2.12. arcsin - Calculate arcsine ΓòÉΓòÉΓòÉ
  3065.  
  3066. PROCEDURE arcsin (z: LONGCOMPLEX): LONGCOMPLEX;
  3067. PROCEDURE arcsin (z: COMPLEX): COMPLEX;
  3068.  
  3069. Modules: ComplexMath, LongComplexMath 
  3070.  
  3071. The function procedure arcsin returns an implementation-defined approximation 
  3072. to the principal value of the complex arcsine of z. 
  3073.  
  3074.  
  3075. ΓòÉΓòÉΓòÉ 4.2.13. arccos - Calculate arccosine ΓòÉΓòÉΓòÉ
  3076.  
  3077. PROCEDURE arccos (z: COMPLEX): COMPLEX;
  3078. PROCEDURE arccos (z: LONGCOMPLEX): LONGCOMPLEX;
  3079.  
  3080. Modules: ComplexMath, LongComplexMath 
  3081.  
  3082. The function procedure arccos returns an implementation-defined approximation 
  3083. to the complex arccosine of z. 
  3084.  
  3085.  
  3086. ΓòÉΓòÉΓòÉ 4.2.14. arctan - Calculate arctangent ΓòÉΓòÉΓòÉ
  3087.  
  3088. PROCEDURE arctan (z: COMPLEX): COMPLEX;
  3089. PROCEDURE arctan (z: LONGCOMPLEX): LONGCOMPLEX;
  3090.  
  3091. Modules: ComplexMath, LongComplexMath 
  3092.  
  3093. The function procedure arctan returns an implementation-defined approximation 
  3094. to the complex arctangent of z. 
  3095.  
  3096.  
  3097. ΓòÉΓòÉΓòÉ 4.2.15. polarToComplex - Convert from polar to complex ΓòÉΓòÉΓòÉ
  3098.  
  3099. PROCEDURE polarToComplex (abs, arg: REAL): COMPLEX;
  3100. PROCEDURE polarToComplex (abs, arg: LONGREAL): LONGCOMPLEX;
  3101.  
  3102. Modules: ComplexMath, LongComplexMath 
  3103.  
  3104. The function procedure polarToComplex returns an implementation-defined 
  3105. approximation to the complex number that has a modulus given by abs and an 
  3106. argument given by arg. 
  3107.  
  3108.  
  3109. ΓòÉΓòÉΓòÉ 4.2.16. scalarMult - Scalar Multiplication ΓòÉΓòÉΓòÉ
  3110.  
  3111. PROCEDURE scalarMult (scalar: REAL;
  3112.                       z: COMPLEX
  3113.                      ): COMPLEX;
  3114. PROCEDURE scalarMult (scalar: LONGREAL;
  3115.                       z: LONGCOMPLEX
  3116.                      ): LONGCOMPLEX;
  3117.  
  3118. Modules: ComplexMath, LongComplexMath 
  3119.  
  3120. The function procedure scalarMult returns an implementation-defined 
  3121. approximation to the scalar product of the real value scalar with the complex 
  3122. value z. 
  3123.  
  3124.  
  3125. ΓòÉΓòÉΓòÉ 4.2.17. IsCMathException - Query exceptional state ΓòÉΓòÉΓòÉ
  3126.  
  3127. PROCEDURE IsCMathException (): BOOLEAN;
  3128. PROCEDURE IsCMathException (): BOOLEAN;
  3129.  
  3130. Modules: ComplexMath, LongComplexMath 
  3131.  
  3132. If the calling coroutine is in the state of exceptional execution because of 
  3133. the raising of a ComplexMath exception, the function procedure 
  3134. ComplexMath.IsCMathException returns TRUE; otherwise it returns FALSE. 
  3135.  
  3136. If the calling coroutine is in the state of exceptional execution because of 
  3137. the raising of a LongComplexMath exception, the function procedure 
  3138. LongComplexMath.IsCMathException returns TRUE; otherwise it returns FALSE. 
  3139.  
  3140.  
  3141. ΓòÉΓòÉΓòÉ 5. Concurrent Programming ΓòÉΓòÉΓòÉ
  3142.  
  3143.      Module Processes 
  3144.      Module Semaphores 
  3145.  
  3146.  
  3147. ΓòÉΓòÉΓòÉ 5.1. Module Processes ΓòÉΓòÉΓòÉ
  3148.  
  3149. The module Processes provides a basic set of facilities for use in concurrent 
  3150. programs. These can be used on their own, or in conjunction with those from the 
  3151. module Semaphores which provide for potentially parallel parts of the program 
  3152. to exclude one another from regions of interaction. 
  3153.  
  3154. A concurrent program consists of a number of processes, each of which may 
  3155. potentially run in parallel with the others but is distinguishable from them. 
  3156. At any one time, a process may be in one of four states: It may be ready, that 
  3157. is, eligible to use the processor but not actually doing so. It may be current, 
  3158. that is, actually using the processor. It may be passive, that is, ineligible 
  3159. to use the processor until another process makes it eligible. Lastly, it may be 
  3160. waiting, that is, ineligible to use the processor until the occurrence of one 
  3161. of a set of events for which it is waiting. 
  3162.  
  3163. At all times there must be at least one process using the processor, or, if no 
  3164. process is eligible, there must be at least one process waiting for some 
  3165. external event. 
  3166.  
  3167. The relationships between these states, together with the operations that lead 
  3168. to a change of state, are depicted in the following figure. Operations given in 
  3169. parentheses are not directly invokable from a program. 
  3170.  
  3171. The picture will be available in the final release. 
  3172.  
  3173. Two general styles of use are envisaged, and both may be present in a single 
  3174. program. 
  3175.  
  3176. In the first style (using Switch), the model is of a set of closely coupled 
  3177. processes, which explicitly choose which of them is to run next, and which pass 
  3178. information between themselves as part of the choice. The intention is to 
  3179. provide a higher level coroutine-like facility between processes of the same 
  3180. urgency. 
  3181.  
  3182. In the second style (using Activate and SuspendMe), the processes are written 
  3183. to be less dependent on one another, and the choice of which of them runs is 
  3184. left to an internal scheduler, which is invoked whenever one process is 
  3185. suspended or another one is reactivated. This internal scheduler makes use of 
  3186. the fact that each process has an associated static `urgency', specified by an 
  3187. INTEGER parameter when it is first created. The scheduler ensures that it 
  3188. cannot be the case that a process eligible to use the processor has an urgency 
  3189. greater than one of the processes currently doing so. The `main process' (the 
  3190. parent program) is given a default urgency of zero; for other processes, the 
  3191. more positive the value of urgency, the more urgent is the process. 
  3192.  
  3193. Those processes that suspend themselves to wait for external events must first 
  3194. associate themselves with one or more sources of such events. The International 
  3195. Standard does not prescribe how events occur, or what the sources of events 
  3196. must be, other than to require that they be mapped in an implementation-defined 
  3197. way to values of the pervasive type CARDINAL, and to require that a source of 
  3198. events cannot be connected to more than one process simultaneously. 
  3199.  
  3200. NOTES: 
  3201.  
  3202.      There is no requirement that pre-emptive scheduling be employed, although 
  3203.       an implementation is free to incorporate such scheduling if this is 
  3204.       desired. 
  3205.  
  3206.      Although the International Standard applies to single-processor machines, 
  3207.       if a pre-emptive (time-sliced) scheduler is present there may 
  3208.       conceptually be more than one `current' process; the description above is 
  3209.       phrased so as to emphasize this. 
  3210.  
  3211.      A program that uses the module Processes should not make explicit use of 
  3212.       coroutines (except, perhaps, in the implementation of Processes itself). 
  3213.  
  3214.      This is a partial specification: Various of the procedures in the modules 
  3215.       Processes and Semaphores have semantics expressed in terms of 
  3216.       preconditions. Their behaviour in situations where these preconditions 
  3217.       are not met is deliberately not specified; in particular, the raising of 
  3218.       exceptions is not required. This is a deliberate decision that allows to 
  3219.       achieve maximum efficiency in the implementation of these modules. 
  3220.  
  3221.  The exceptions raised by Processes are identified by the values of the 
  3222.  enumeration type ProcessesExceptions: 
  3223.  
  3224.   TYPE
  3225.     ProcessesExceptions = (passiveProgram, processError);
  3226.  
  3227.  The detection of the exception processError is implementation-defined. 
  3228.  
  3229.  After the module is initialized, there is exactly one process, known as the 
  3230.  `main process'. This process have an urgency of 0 and a parameter of NIL; 
  3231.  initially, it is not associated with any source of events. 
  3232.  
  3233.  CHANGE: 
  3234.  
  3235.  This module is not based on the module Processes described in Programming in 
  3236.  Modula-2. 
  3237.  
  3238.      Types of Processes 
  3239.      The Procedures of Processes 
  3240.      Create - Create new process 
  3241.      Start - Start new process 
  3242.      StopMe - Terminate calling process 
  3243.      SuspendMe - Suspend calling process 
  3244.      Activate - Activate process 
  3245.      SuspendMeAndActivate - Suspend current process and activate another 
  3246.      Switch - Switch to another process 
  3247.      Wait - Wait for event 
  3248.      Attach - Associate event source 
  3249.      Detach - Dissociate event source 
  3250.      IsAttached - Query event source 
  3251.      Handler - Query event handler 
  3252.      Me - Query current process id 
  3253.      MyParam - Query current process parameter 
  3254.      UrgencyOf - Query process urgency 
  3255.      IsProcessesException - Query exceptional state 
  3256.      ProcessesException - Query exception id 
  3257.  
  3258.  
  3259. ΓòÉΓòÉΓòÉ 5.1.1. Types of Processes ΓòÉΓòÉΓòÉ
  3260.  
  3261. TYPE
  3262.   ProcessId;
  3263.     (* Used to identify processes *)
  3264.   Parameter = SYSTEM.ADDRESS;
  3265.     (* Used to pass data between processes *)
  3266.   Body = PROC;
  3267.     (* Used as the type of a process body *)
  3268.   Urgency = INTEGER;
  3269.     (* Used by the internal scheduler *)
  3270.   Sources = CARDINAL;
  3271.     (* Used to identify event sources *)
  3272.  
  3273.  
  3274. ΓòÉΓòÉΓòÉ 5.1.2. The Procedures of Processes ΓòÉΓòÉΓòÉ
  3275.  
  3276. The semantics of certain of the procedures of Processes require that a process 
  3277. be selected from the set of processes that are eligible to run, and be 
  3278. scheduled for execution. The selection algorithm shall guarantee that no 
  3279. process eligible to use the processor has an urgency greater than one of the 
  3280. processes currently doing so. 
  3281.  
  3282. NOTES: 
  3283.  
  3284.      The procedures in this category are Start, StopMe, SuspendMe, Activate, 
  3285.       SuspendMeAndActivate and Wait. 
  3286.  
  3287.      The urgency of a process is specified, when it is created, by a value of 
  3288.       the type INTEGER, and cannot be changed dynamically. The more positive 
  3289.       the value of urgency, the more urgent the process. 
  3290.  
  3291.  Certain of the procedures of Processes require that a process be associated 
  3292.  with a source of external events. There shall be an implementation-defined 
  3293.  mapping of values of the type CARDINAL to such sources of events. 
  3294.  
  3295.  A source of events shall not be associated with more than one process at any 
  3296.  instant. 
  3297.  
  3298.  NOTES: 
  3299.  
  3300.      The International Standard does not prescribe how events occur, or what 
  3301.       the sources of events must be, other than in terms of this 
  3302.       implementation-defined mapping. 
  3303.  
  3304.      The International Standard does not specify the consequences if a value 
  3305.       (of the type Sources) that is not mapped to a source of events is passed 
  3306.       as an actual parameter to any of the procedures Attach, Detach, 
  3307.       IsAttached or Handler. 
  3308.  
  3309.  
  3310. ΓòÉΓòÉΓòÉ 5.1.3. Create - Create new process ΓòÉΓòÉΓòÉ
  3311.  
  3312. PROCEDURE Create (procBody: Body;
  3313.                   extraSpace: CARDINAL;
  3314.                   procUrg: Urgency;
  3315.                   procParams: Parameter;
  3316.                   VAR procId: ProcessId);
  3317.  
  3318. Module Processes 
  3319.  
  3320. The procedure Create creates a new process. An unique value of the type 
  3321. ProcessId is assigned to procId as an identity for the process. The urgency and 
  3322. parameters for the created process are those given by procUrg and procParams 
  3323. respectively. extraSpace specifies the amount of workspace (in units of 
  3324. SYSTEM.LOC) that is required by the process, above any fixed overhead needed by 
  3325. the implementation of Processes. 
  3326.  
  3327. The process will be ineligible to run (i.e. it is created in the passive 
  3328. state). When the process is first activated, it will start execution by 
  3329. invoking the procedure that is denoted by procBody. 
  3330.  
  3331. The usage made of the workspace is implementation-dependent. 
  3332.  
  3333. If the end of this procedure body is reached, or if a return statement is 
  3334. executed in the procedure body, then the effect will be the same as calling the 
  3335. protection domain exit procedure (if any), followed by an explicit call of 
  3336. StopMe. 
  3337.  
  3338. NOTES: 
  3339.  
  3340.      The process will be activated when another process makes it eligible by 
  3341.       calling Switch or Activate or SuspendMeAndActivate. 
  3342.  
  3343.      The standard library makes no provision to handle exceptions generated by 
  3344.       created processes, which must handle all exceptions themselves if it is 
  3345.       wished to avoid exceptional termination of a program. 
  3346.  
  3347.  
  3348. ΓòÉΓòÉΓòÉ 5.1.4. Start - Start new process ΓòÉΓòÉΓòÉ
  3349.  
  3350. PROCEDURE Start (procBody: Body;
  3351.                  extraSpace: CARDINAL;
  3352.                  procUrg: Urgency;
  3353.                  procParams: Parameter;
  3354.                  VAR procId: ProcessId);
  3355.  
  3356. Module Processes 
  3357.  
  3358. The procedure Start have an identical effect to the procedure Create, except 
  3359. that the created process will be eligible to run immediately (i.e. it is 
  3360. created in the ready state). 
  3361.  
  3362.  
  3363. ΓòÉΓòÉΓòÉ 5.1.5. StopMe - Terminate calling process ΓòÉΓòÉΓòÉ
  3364.  
  3365. PROCEDURE StopMe ();
  3366.  
  3367. Module Processes 
  3368.  
  3369. If the calling process is not associated with any source of events, the 
  3370. procedure StopMe causes the calling process to be terminated and removed from 
  3371. the system. The procedure does not return; the calling process will not again 
  3372. become eligible to run. If there are no other processes, then normal 
  3373. termination of the program is initiated. If there are other processes eligible 
  3374. to run, then one of them is selected for execution. The exception 
  3375. passiveProgram is raised if there are other processes, but none of them is 
  3376. eligible to run and none of them is waiting for an event to occur. 
  3377.  
  3378. NOTES: 
  3379.  
  3380.      If the main process stops, the other processes will continue to run. 
  3381.  
  3382.      The behaviour of StopMe in situations where the calling process is 
  3383.       associated with a source of events is implementation-dependent. 
  3384.  
  3385.  
  3386. ΓòÉΓòÉΓòÉ 5.1.6. SuspendMe - Suspend calling process ΓòÉΓòÉΓòÉ
  3387.  
  3388. PROCEDURE SuspendMe ();
  3389.  
  3390. Module Processes 
  3391.  
  3392. The procedure SuspendMe causes the calling process to become ineligible to run 
  3393. (i.e. to enter the passive state). If there are other processes eligible to 
  3394. run, then one of them is selected for execution. The exception passiveProgram 
  3395. is raised if no other process is eligible to run and no other process is 
  3396. waiting for an event to occur. 
  3397.  
  3398. NOTE: 
  3399.  
  3400. The suspended process can be reactivated when another process again makes it 
  3401. eligible by calling Switch or Activate or SuspendMeAndActivate. 
  3402.  
  3403.  
  3404. ΓòÉΓòÉΓòÉ 5.1.7. Activate - Activate process ΓòÉΓòÉΓòÉ
  3405.  
  3406. PROCEDURE Activate (procId: ProcessId);
  3407.  
  3408. Module Processes 
  3409.  
  3410. If the process identified by procId is passive or waiting, the procedure 
  3411. Activate causes that process to become eligible to run (i.e. to enter the ready 
  3412. state); otherwise it have no effect. 
  3413.  
  3414. NOTE: 
  3415.  
  3416. If the designated process was suspended by a call of Wait, it will become ready 
  3417. in the same way as if the event had occurred. Thus, if the procedure Activate 
  3418. (or SuspendMeAndActivate) is used to reactivate a waiting process, further 
  3419. checking will usually be required in that process to determine whether or not 
  3420. the event for which it was waiting had actually taken place. 
  3421.  
  3422.  
  3423. ΓòÉΓòÉΓòÉ 5.1.8. SuspendMeAndActivate - Suspend current process and activate another ΓòÉΓòÉΓòÉ
  3424.  
  3425. PROCEDURE SuspendMeAndActivate (procId: ProcessId);
  3426.  
  3427. Module Processes 
  3428.  
  3429. If the process identified by procId is passive, waiting, or is the calling 
  3430. process, the procedure SuspendMeAndActivate causes the calling process to 
  3431. become ineligible to run (i.e. to enter the passive state), and causes the 
  3432. process identified by procId to become eligible to run (i.e. to enter the ready 
  3433. state); otherwise the call have no effect. 
  3434.  
  3435. NOTE 
  3436.  
  3437. SuspendMeAndActivate(procId) effectively performs an atomic (i.e. 
  3438. `indivisible') sequence of the calls SuspendMe() and Activate(procId). If 
  3439. applied to the identity of the calling process, the effect is to force a 
  3440. scheduling operation. 
  3441.  
  3442.  
  3443. ΓòÉΓòÉΓòÉ 5.1.9. Switch - Switch to another process ΓòÉΓòÉΓòÉ
  3444.  
  3445. PROCEDURE Switch (procId: ProcessId; VAR info: Parameter);
  3446.  
  3447. Module Processes 
  3448.  
  3449. If the calling process has an urgency no greater than that of the process 
  3450. identified by procId, the procedure Switch causes the calling process to become 
  3451. ineligible to run (i.e. to enter the passive state), and resumes execution of 
  3452. the process identified by procId. The exception processError occurs (but need 
  3453. not be raised) if this process is already eligible to run. info is passed as a 
  3454. parameter to the process identified by procId. If the calling process is 
  3455. reactivated as a result of another process calling Switch, then info is 
  3456. assigned the value passed by that other call. If the calling process is 
  3457. reactivated as a result of another process calling Activate or 
  3458. SuspendMeAndActivate, then info is assigned the value NIL. 
  3459.  
  3460. NOTE: 
  3461.  
  3462. Switch is intended to allow a high-level coroutine facility for use within 
  3463. concurrent programs. Several consequences follow: 
  3464.  
  3465.    1. The process that is resumed will only be able to retrieve the parameter 
  3466.       passed to it as info if it was ineligible to run by virtue of itself 
  3467.       having called Switch. 
  3468.  
  3469.    2. The behaviour of Switch in situations where the urgency of the calling 
  3470.       process is greater than the urgency of the process identified by procId 
  3471.       is implementation-dependent. 
  3472.  
  3473.    3. While a call of Switch may be used instead of Activate to activate a 
  3474.       process, p, of a higher urgency than the caller, p will not be able to 
  3475.       use Switch if it wishes to reactivate that caller; it will be obliged to 
  3476.       use Activate or SuspendMeAndActivate. 
  3477.  
  3478.    4. If the designated process was suspended by a call of Wait, it will become 
  3479.       ready in the same way as if the event had occurred. Thus, if the 
  3480.       procedure Switch (or Activate or SuspendMeAndActivate) is used to 
  3481.       reactivate a waiting process, further checking will usually be required 
  3482.       in that process to determine whether or not the event for which it was 
  3483.       waiting had actually taken place. 
  3484.  
  3485.  
  3486. ΓòÉΓòÉΓòÉ 5.1.10. Wait - Wait for event ΓòÉΓòÉΓòÉ
  3487.  
  3488. PROCEDURE Wait ();
  3489.  
  3490. Module Processes 
  3491.  
  3492. The procedure Wait causes the calling process to become ineligible to run (i.e. 
  3493. to enter the waiting state) if it is associated with a source of events. If 
  3494. there are other processes eligible to run, then one of them is selected for 
  3495. execution. 
  3496.  
  3497. NOTES: 
  3498.  
  3499.      One of the ready processes is selected for execution to replace the 
  3500.       caller of Wait. This is on the assumption that, if there are ready 
  3501.       processes that are not executing, the scheduler imposes a fixed upper 
  3502.       limit on the number of executing processes. 
  3503.  
  3504.      The process will remain ineligible to run until an event occurs from one 
  3505.       of the sources to which it is attached, or until it is made eligible by 
  3506.       another process calling Switch or Activate or SuspendMeAndActivate. 
  3507.  
  3508.      If a process waiting for an event is reactivated by virtue of a call 
  3509.       being made by another process to Switch or Activate or 
  3510.       SuspendMeAndActivate, it will become ready in the same way as if the 
  3511.       event had occurred. Thus, in such situations, further checking will 
  3512.       usually be required to determine whether or not the event for which it 
  3513.       was waiting had actually taken place. 
  3514.  
  3515.      The behaviour of Wait if the calling process has not been attached to a 
  3516.       source of events, or if another process is attached to the event source 
  3517.       after the calling process has called Wait is implementation-dependent. In 
  3518.       such circumstances the calling process may never again become eligible to 
  3519.       run, and the system could deadlock. 
  3520.  
  3521.  
  3522. ΓòÉΓòÉΓòÉ 5.1.11. Attach - Associate event source ΓòÉΓòÉΓòÉ
  3523.  
  3524. PROCEDURE Attach (eventSource: Sources);
  3525.  
  3526. Module Processes 
  3527.  
  3528. The procedure Attach associates the source of events given by eventSource with 
  3529. the calling process. If the source of events is already associated with a 
  3530. process, then that association is first broken. 
  3531.  
  3532.  
  3533. ΓòÉΓòÉΓòÉ 5.1.12. Detach - Dissociate event source ΓòÉΓòÉΓòÉ
  3534.  
  3535. PROCEDURE Detach (eventSource: Sources);
  3536.  
  3537. Module Processes 
  3538.  
  3539. The procedure Detach dissociates the source of events given by eventSource from 
  3540. the program. 
  3541.  
  3542. NOTE: 
  3543.  
  3544. Detach has no effect if the program is not associated with eventSource. 
  3545.  
  3546.  
  3547. ΓòÉΓòÉΓòÉ 5.1.13. IsAttached - Query event source ΓòÉΓòÉΓòÉ
  3548.  
  3549. PROCEDURE IsAttached (eventSource: Sources): BOOLEAN;
  3550.  
  3551. Module Processes 
  3552.  
  3553. The function procedure IsAttached returns TRUE if and only if the source of 
  3554. events given by eventSource is associated with one of the processes in the 
  3555. program. 
  3556.  
  3557.  
  3558. ΓòÉΓòÉΓòÉ 5.1.14. Handler - Query event handler ΓòÉΓòÉΓòÉ
  3559.  
  3560. PROCEDURE Handler (eventSource: Sources): ProcessId;
  3561.  
  3562. Module Processes 
  3563.  
  3564. If the source of events identified by eventSource is associated with a process, 
  3565. the function procedure Handler is the identity of that process. 
  3566.  
  3567. NOTE: 
  3568.  
  3569. The value of the call Handler(eventSource) is implementation-dependent in the 
  3570. situation where the value of eventSource is not mapped to any real source of 
  3571. events. 
  3572.  
  3573.  
  3574. ΓòÉΓòÉΓòÉ 5.1.15. Me - Query current process id ΓòÉΓòÉΓòÉ
  3575.  
  3576. PROCEDURE Me (): ProcessId;
  3577.  
  3578. Module Processes 
  3579.  
  3580. The function procedure Me returns the identity of the calling process. 
  3581.  
  3582.  
  3583. ΓòÉΓòÉΓòÉ 5.1.16. MyParam - Query current process parameter ΓòÉΓòÉΓòÉ
  3584.  
  3585. PROCEDURE MyParam (): Parameter;
  3586.  
  3587. Module Processes 
  3588.  
  3589. The function procedure MyParam returns the value of the parameter denoted by 
  3590. procParams at the time the process was created. 
  3591.  
  3592.  
  3593. ΓòÉΓòÉΓòÉ 5.1.17. UrgencyOf - Query process urgency ΓòÉΓòÉΓòÉ
  3594.  
  3595. PROCEDURE UrgencyOf (procId: ProcessId): Urgency;
  3596.  
  3597. Module Processes 
  3598.  
  3599. The function procedure UrgencyOf returns the urgency of the process identified 
  3600. by procId. 
  3601.  
  3602. NOTE: 
  3603.  
  3604. This urgency of a process is statically assigned when the process is created; 
  3605. it is not possible for a process to alter its urgency dynamically. 
  3606.  
  3607.  
  3608. ΓòÉΓòÉΓòÉ 5.1.18. IsProcessesException - Query exceptional state ΓòÉΓòÉΓòÉ
  3609.  
  3610. PROCEDURE IsProcessesException (): BOOLEAN;
  3611.  
  3612. Module Processes 
  3613.  
  3614. If the calling coroutine is in the state of exceptional execution because of 
  3615. the raising of a Processes exception, the function procedure 
  3616. IsProcessesException returns TRUE; otherwise it retruns FALSE. 
  3617.  
  3618.  
  3619. ΓòÉΓòÉΓòÉ 5.1.19. ProcessesException - Query exception id ΓòÉΓòÉΓòÉ
  3620.  
  3621. PROCEDURE ProcessesException (): ProcessesExceptions;
  3622.  
  3623. Module Processes 
  3624.  
  3625. If the calling coroutine is in the state of exceptional execution because of 
  3626. the raising of a Processes exception, the function procedure ProcessesException 
  3627. returns the value that identifies the raised exception; otherwise the language 
  3628. exception exException is be raised. 
  3629.  
  3630.  
  3631. ΓòÉΓòÉΓòÉ 5.2. Module Semaphores ΓòÉΓòÉΓòÉ
  3632.  
  3633. The module Semaphores provides facilities for potentially parallel parts of a 
  3634. program (i.e. processes) to exclude one another from regions of interaction by 
  3635. using the semaphore mechanism first proposed by Dijkstra. The semaphores 
  3636. provided by the module are general or counting semaphores (as opposed to binary 
  3637. semaphores). 
  3638.  
  3639. The hidden type SEMAPHORE is used to identify semaphores. 
  3640.  
  3641. TYPE
  3642.   SEMAPHORE;
  3643.  
  3644. Each semaphore have a unique identity. Associated with each semaphore there is 
  3645. a non-negative count, and a set of zero or more processes waiting for it to 
  3646. become free. A semaphore is said to be `free' if its associated count is 
  3647. non-zero. 
  3648.  
  3649. After the module has been initialized, no semaphores are in existence. 
  3650.  
  3651. NOTES: 
  3652.  
  3653.      For convenience, the semantics of this module are illustrated in terms of 
  3654.       the semantics of the Processes module. However, there is no requirement 
  3655.       that an implementation provide Processes in addition to providing 
  3656.       Semaphores. 
  3657.  
  3658.      The behaviour of the procedures Destroy, Claim, Release and CondClaim in 
  3659.       situations where the actual parameter passed is not a valid semaphore 
  3660.       (i.e. is not the identity of a semaphore allocated by a call to Create) 
  3661.       is implementation-dependent. 
  3662.  
  3663.      Create - Create new semaphore 
  3664.      Destroy - Destroy semaphore 
  3665.      Claim - Claim semaphore 
  3666.      Release - Unclaim semaphore 
  3667.      CondClaim - Claim semaphore safely 
  3668.      IsSemaphoresException - Query exceptional state 
  3669.  
  3670.  
  3671. ΓòÉΓòÉΓòÉ 5.2.1. Create - Create new semaphore ΓòÉΓòÉΓòÉ
  3672.  
  3673. PROCEDURE Create (VAR s: SEMAPHORE; initialCount: CARDINAL);
  3674.  
  3675. Module Semaphores 
  3676.  
  3677. The procedure Create creates a new semaphore, if there are sufficient resources 
  3678. to do so, and assigns its identity to s; otherwise the Semaphores exception is 
  3679. raised. The count associated with the semaphore is initialized to initialCount, 
  3680. and there will then be no process waiting for the semaphore to be free. 
  3681.  
  3682.  
  3683. ΓòÉΓòÉΓòÉ 5.2.2. Destroy - Destroy semaphore ΓòÉΓòÉΓòÉ
  3684.  
  3685. PROCEDURE Destroy (VAR s: SEMAPHORE);
  3686.  
  3687. Module Semaphores 
  3688.  
  3689. Provided that no process is waiting for the semaphore identified by the value 
  3690. of s to become free, the procedure Destroy removes that semaphore and recovers 
  3691. the resources used to implement it. 
  3692.  
  3693. The variable s is set to a value that is invalid for semaphore operations. 
  3694.  
  3695. NOTE: 
  3696.  
  3697. The behaviour of Destroy(s) in situations where there are processes waiting for 
  3698. s to become free is implementation-dependent. 
  3699.  
  3700.  
  3701. ΓòÉΓòÉΓòÉ 5.2.3. Claim - Claim semaphore ΓòÉΓòÉΓòÉ
  3702.  
  3703. PROCEDURE Claim (s: SEMAPHORE);
  3704.  
  3705. Module Semaphores 
  3706.  
  3707. The procedure Claim claims the semaphore identified by s. If the count 
  3708. associated with s is non-zero, then it is decremented, and the calling process 
  3709. continues execution; otherwise the calling process becomes ineligible to run, 
  3710. and is added to the set waiting for s to become free. 
  3711.  
  3712.  
  3713. ΓòÉΓòÉΓòÉ 5.2.4. Release - Unclaim semaphore ΓòÉΓòÉΓòÉ
  3714.  
  3715. PROCEDURE Release (s: SEMAPHORE);
  3716.  
  3717. Module Semaphores 
  3718.  
  3719. The procedure Release unclaims the semaphore identified by s. If no process is 
  3720. waiting on s, the count associated with s is incremented; otherwise one process 
  3721. is selected from those waiting for s to become free; this process is removed 
  3722. from the waiting set, and becomes eligible to run (i.e. enter the ready state). 
  3723.  
  3724. NOTES: 
  3725.  
  3726.      No requirement is imposed about which of the waiting processes is chosen 
  3727.       for activation. 
  3728.  
  3729.      Preemption occurs if the newly eligible process has an urgency greater 
  3730.       than that of the calling process. 
  3731.  
  3732.  
  3733. ΓòÉΓòÉΓòÉ 5.2.5. CondClaim - Claim semaphore safely ΓòÉΓòÉΓòÉ
  3734.  
  3735. PROCEDURE CondClaim (s: SEMAPHORE): BOOLEAN;
  3736.  
  3737. Module Semaphores 
  3738.  
  3739. If the call Claim(s) would have caused the calling process to become ineligible 
  3740. to run, the procedure CondClaim returns FALSE, and the count associated with s 
  3741. is unchanged. Otherwise the count associated with s is decremented, and the 
  3742. procedure returns TRUE. 
  3743.  
  3744. NOTE: 
  3745.  
  3746. The calling process is never suspended as a result of calling CondClaim. 
  3747.  
  3748.  
  3749. ΓòÉΓòÉΓòÉ 5.2.6. IsSemaphoresException - Query exceptional state ΓòÉΓòÉΓòÉ
  3750.  
  3751. PROCEDURE IsSemaphoresException (): BOOLEAN;
  3752.  
  3753. Module Semaphores 
  3754.  
  3755. If the calling coroutine is in the state of exceptional execution because of 
  3756. the raising of the Semaphores exception, the procedure IsSemaphoresException 
  3757. returns TRUE; otherwise it returns FALSE. 
  3758.  
  3759.  
  3760. ΓòÉΓòÉΓòÉ 6. String Manipulation ΓòÉΓòÉΓòÉ
  3761.  
  3762.      Module Strings 
  3763.  
  3764.  
  3765. ΓòÉΓòÉΓòÉ 6.1. Module Strings ΓòÉΓòÉΓòÉ
  3766.  
  3767. The module Strings provides facilities for manipulating character arrays as 
  3768. representations of strings. The procedures provided accept any character array 
  3769. type, but manipulate all as if their index types were whole numbers and 
  3770. zero-based. 
  3771.  
  3772. The module also provides predicates that check whether an operation to assign, 
  3773. delete, insert, replace or append strings or characters will work without loss 
  3774. of information. These predicates check that parameters indexing the concrete 
  3775. representation of a string (i.e. the character array containing the string 
  3776. value) fall within its length, thereby allowing the programmer to maintain the 
  3777. string abstraction. 
  3778.  
  3779. A general-purpose string type String1 is provided for convenience when handling 
  3780. single characters by using a value constructor. An enumeration type 
  3781. CompareResults is provided for use when comparing string values: 
  3782.  
  3783. TYPE
  3784.   String1 = ARRAY [0..0] OF CHAR;
  3785.  
  3786.   CompareResults = (less, equal, greater);
  3787.  
  3788. NOTES: 
  3789.  
  3790.      The procedures provided accept any character array type (i.e. with any 
  3791.       index type) but because of the use of open array parameters the 
  3792.       procedures manipulate all as if their index types were whole numbers and 
  3793.       zero-based. 
  3794.  
  3795.      The array type String1 may be used as the array type identifier of an 
  3796.       array constructor when constructing an array value from a value of the 
  3797.       character type. The constructed array value may be used as actual 
  3798.       parameter in calls of procedures having a formal open array value 
  3799.       parameter, for example to assign, insert, replace, append, concatenate, 
  3800.       or find a single character. 
  3801.  
  3802.      Since function procedures cannot return open arrays, many of the 
  3803.       operations that might more logically have been provided as function 
  3804.       procedures have to be provided as proper procedures. 
  3805.  
  3806.      Predicates with the prefix `Can' and the suffix `All' are provided to 
  3807.       check the operation-completion condition of string operations (e.g. 
  3808.       CanInsertAll checks the operation-completion condition for Insert). 
  3809.       Failure to satisfy the operation-completion condition of a string 
  3810.       handling procedure does not lead to an exception; i.e. the semantics of 
  3811.       string operations are defined for all well-formed parameters. 
  3812.  
  3813.      Value parameters are used where a string value is not changed by a 
  3814.       procedure. This is not just a matter of programming clarity, but allows 
  3815.       the parameterization of programs using constants. 
  3816.  
  3817.      Because string constants cannot be assigned to, nor appended to, nor have 
  3818.       characters replaced or inserted, the predicates that test the operation 
  3819.       completion conditions of procedures use VAR-parameters for the string 
  3820.       parameters. 
  3821.  
  3822.      The International Standard has not adopted a change to Modula-2 
  3823.       (described in the fourth edition of Programming in Modula-2) of always 
  3824.       requiring a string terminator for a string value. 
  3825.  
  3826.      Length - Query string length 
  3827.      CanAssignAll - Check whether Assign will succeed 
  3828.      Assign - Assign string value 
  3829.      CanExtractAll - Check whether Extract will succeed 
  3830.      Extract - Extract substring 
  3831.      CanDeleteAll - Check whether Delete will succeed 
  3832.      Delete - Delete substring 
  3833.      CanInsertAll - Check whether Insert will succeed 
  3834.      Insert - Insert substring 
  3835.      CanReplaceAll - Check whether Replace will succeed 
  3836.      Replace - Replace substring 
  3837.      CanAppendAll - Check whether Append will succeed 
  3838.      Append - Append string 
  3839.      CanConcatAll - Check whether Concat will succeed 
  3840.      Concat - Concatenate strings 
  3841.      Capitalize - Capitalize string 
  3842.      Compare - Compare strings 
  3843.      Equal - Compare strings 
  3844.      FindNext - Search string forward 
  3845.      FindPrev - Search string backward 
  3846.      FindDiff - Find position of string difference 
  3847.  
  3848.  
  3849. ΓòÉΓòÉΓòÉ 6.1.1. Length - Query string length ΓòÉΓòÉΓòÉ
  3850.  
  3851. PROCEDURE Length (stringVal: ARRAY OF CHAR): CARDINAL;
  3852.  
  3853. Module Strings 
  3854.  
  3855. The function procedure Length returns the length of the string value in 
  3856. stringVal. This is the same as the value of LENGTH(stringVal). 
  3857.  
  3858.  
  3859. ΓòÉΓòÉΓòÉ 6.1.2. CanAssignAll - Check whether Assign will succeed ΓòÉΓòÉΓòÉ
  3860.  
  3861. PROCEDURE CanAssignAll (sourceLength: CARDINAL;
  3862.                         VAR destination: ARRAY OF CHAR
  3863.                        ): BOOLEAN;
  3864.  
  3865. Module Strings 
  3866.  
  3867. The function procedure CanAssignAll returns the value of the Boolean expression 
  3868. sourceLength <= HIGH(destination) + 1 
  3869.  
  3870. NOTES: 
  3871.  
  3872.      CanAssignAll may be used to check whether complete assignment of a string 
  3873.       value to a string variable will be possible using, for example, the 
  3874.       procedure Assign. 
  3875.  
  3876.      Since a string variable must have at least one element, single-character 
  3877.       string assignment is always valid. 
  3878.  
  3879.  
  3880. ΓòÉΓòÉΓòÉ 6.1.3. Assign - Assign string value ΓòÉΓòÉΓòÉ
  3881.  
  3882. PROCEDURE Assign (source: ARRAY OF CHAR;
  3883.                   VAR destination: ARRAY OF CHAR);
  3884.  
  3885. Module Strings 
  3886.  
  3887. The procedure Assign assigns the string value in source to destination. If the 
  3888. length of source exceeds the capacity of destination, the assigned value is 
  3889. truncated to the capacity of destination. If the length of source is less than 
  3890. the capacity of destination, a string terminator is appended to source when 
  3891. assignment takes place. 
  3892.  
  3893. EXAMPLE - String assignment. 
  3894.  
  3895. In these, and later, examples the following declarations are assumed: 
  3896.  
  3897. VAR
  3898.   small: ARRAY [0 .. 4] OF CHAR;
  3899.   large: ARRAY [0 .. 255] OF CHAR;
  3900.   alpha: ARRAY ['A' .. 'E'] OF CHAR;
  3901.   ch: CHAR;
  3902.   found, areDiff: BOOLEAN;
  3903.   pos: CARDINAL;
  3904.  
  3905.    1. ch := "X"; 
  3906.       Assign(String1{ch}, small) 
  3907.       results in small having value "X" 
  3908.  
  3909.    2. Assign("pq", small) 
  3910.       results in small having value "pq" 
  3911.  
  3912.    3. Assign("", small) 
  3913.       results in small having value "" 
  3914.  
  3915.    4. Assign("Hello!", small) 
  3916.       results in small having value "Hello" without string terminator 
  3917.  
  3918.    5. the call 
  3919.       CanAssignAll(6, small) 
  3920.       returns the value FALSE 
  3921.  
  3922.    6. Assign("Go", alpha) 
  3923.       results in alpha having value "Go" 
  3924.  
  3925.    7. small := "Hello"; large := ""; 
  3926.       IF CanAssignAll(LENGTH(small), large) 
  3927.       THEN 
  3928.         Assign(small, large) 
  3929.       END 
  3930.       results in large having value "Hello" 
  3931.  
  3932.  
  3933. ΓòÉΓòÉΓòÉ 6.1.4. CanExtractAll - Check whether Extract will succeed ΓòÉΓòÉΓòÉ
  3934.  
  3935. PROCEDURE CanExtractAll (sourceLength,
  3936.                          startPos,
  3937.                          numberToExtract: CARDINAL;
  3938.                          VAR destination: ARRAY OF CHAR
  3939.                         ): BOOLEAN;
  3940.  
  3941. Module Strings 
  3942.  
  3943. The function procedure CanExtractAll returns the value of the Boolean 
  3944. expression 
  3945. (startPos + numberToExtract <= sourceLength) AND 
  3946. (numberToExtract <= HIGH(destination) + 1) 
  3947.  
  3948. NOTE: 
  3949.  
  3950. CanExtractAll may be used to check whether complete extraction of a substring 
  3951. from a string variable will be possible using, for example, the procedure 
  3952. Extract. 
  3953.  
  3954.  
  3955. ΓòÉΓòÉΓòÉ 6.1.5. Extract - Extract substring ΓòÉΓòÉΓòÉ
  3956.  
  3957. PROCEDURE Extract (source: ARRAY OF CHAR;
  3958.                    startPos,
  3959.                    numberToExtract: CARDINAL;
  3960.                    VAR destination: ARRAY OF CHAR);
  3961.  
  3962. Module Strings 
  3963.  
  3964. The procedure Extract creates a new string value of at most numberToExtract 
  3965. characters extracted from source. Extraction starts at position startPos in 
  3966. source, and continues as long as there are characters left to extract from 
  3967. source and no more than numberToExtract characters have been extracted. If the 
  3968. length of the created string value exceeds the capacity of destination, the 
  3969. string value is truncated to the capacity of destination, and the truncated 
  3970. value is assigned to destination. If the length of the created string value is 
  3971. less than the capacity of destination, a string terminator is appended to the 
  3972. string value, and the resulting value is assigned to destination. An empty 
  3973. string value is extracted if startPos is greater than or equal to 
  3974. LENGTH(source). 
  3975.  
  3976. EXAMPLE - String extraction. 
  3977.  
  3978.    1. large := "ABCDE"; small := ""; 
  3979.       IF CanExtractAll(LENGTH (large), 2, 3, small) THEN 
  3980.         Extract(large, 2, 3, small) 
  3981.       END 
  3982.       results in small having value "CDE" 
  3983.  
  3984.    2. large := "ABCDE"; small := ""; 
  3985.       Extract(large, 2, 3, small) 
  3986.       results in small having value "CDE" 
  3987.  
  3988.  
  3989. ΓòÉΓòÉΓòÉ 6.1.6. CanDeleteAll - Check whether Delete will succeed ΓòÉΓòÉΓòÉ
  3990.  
  3991. PROCEDURE CanDeleteAll (stringLength,
  3992.                         startPos,
  3993.                         numberToDelete: CARDINAL
  3994.                        ): BOOLEAN;
  3995.  
  3996. Module Strings 
  3997.  
  3998. The function procedure CanDeleteAll returns the value of the Boolean expression 
  3999. startPos + numberToDelete <= stringLength 
  4000.  
  4001. NOTE: 
  4002.  
  4003. CanDeleteAll may be used to check whether complete deletion of a substring 
  4004. value from a string variable will be possible using, for example, the procedure 
  4005. Delete. 
  4006.  
  4007.  
  4008. ΓòÉΓòÉΓòÉ 6.1.7. Delete - Delete substring ΓòÉΓòÉΓòÉ
  4009.  
  4010. PROCEDURE Delete (VAR stringVar: ARRAY OF CHAR;
  4011.                   startPos,
  4012.                   numberToDelete: CARDINAL);
  4013.  
  4014. Module Strings 
  4015.  
  4016. The procedure Delete creates a new string value by deleting at most 
  4017. numberToDelete characters from stringVar. Deletion starts at position startPos 
  4018. in stringVar and continues as long as there are characters left to delete in 
  4019. stringVar and no more than numberToDelete characters have been deleted. If any 
  4020. characters are deleted, a string terminator is appended to the created string 
  4021. value, and the resulting value is assigned to stringVar. The string value in 
  4022. stringVar is not altered if startPos is greater than or equal to 
  4023. LENGTH(stringVar). 
  4024.  
  4025. EXAMPLE - String deletion. 
  4026.  
  4027.    1. small := "ABCDE"; 
  4028.       IF CanDeleteAll(LENGTH(small), 2, 2) THEN 
  4029.         Delete(small, 2, 2) 
  4030.       END 
  4031.       results in small having value "ABE" 
  4032.  
  4033.    2. after the assignment 
  4034.         small := "ABC"; 
  4035.       the call 
  4036.         CanDeleteAll(3, 2, 2) 
  4037.       returns the value FALSE 
  4038.  
  4039.    3. small := "ABC"; 
  4040.       Delete(small, 2, 2) 
  4041.       results in small having value "AB" 
  4042.  
  4043.  
  4044. ΓòÉΓòÉΓòÉ 6.1.8. CanInsertAll - Check whether Insert will succeed ΓòÉΓòÉΓòÉ
  4045.  
  4046. PROCEDURE CanInsertAll (sourceLength, startPos: CARDINAL;
  4047.                         VAR destination: ARRAY OF CHAR
  4048.                        ): BOOLEAN;
  4049.  
  4050. Module Strings 
  4051.  
  4052. The function procedure CanInsertAll returns the value of the Boolean expression 
  4053. (startPos <= LENGTH(destination)) AND 
  4054. (sourceLength + LENGTH(destination) <= HIGH(destination) + 1) 
  4055.  
  4056. NOTE: 
  4057.  
  4058. CanInsertAll may be used to check whether complete insertion of a string value 
  4059. into a string variable will be possible using, for example, the procedure 
  4060. Insert. 
  4061.  
  4062.  
  4063. ΓòÉΓòÉΓòÉ 6.1.9. Insert - Insert substring ΓòÉΓòÉΓòÉ
  4064.  
  4065. PROCEDURE Insert (source: ARRAY OF CHAR;
  4066.                   startPos: CARDINAL;
  4067.                   VAR destination: ARRAY OF CHAR);
  4068.  
  4069. Module Strings 
  4070.  
  4071. The procedure Insert creates a new string value by inserting the substring 
  4072. source into destination. The string in destination is first splitted at the 
  4073. position given by startPos; the created string value is the concatenation of 
  4074. the first part of destination, the substring source, and the second part of 
  4075. destination. If the length of the created string value exceeds the capacity of 
  4076. destination, the string value is truncated to the capacity of destination, and 
  4077. the truncated value is assigned to destination. If the length of the created 
  4078. string value is less than the capacity of destination, a string terminator is 
  4079. appended to the string value, and the resulting value is assigned to 
  4080. destination. The string value in destination is not altered if startPos is 
  4081. greater than or equal to LENGTH(destination). 
  4082.  
  4083. EXAMPLE - String insertion. 
  4084.  
  4085.    1. after the assignment 
  4086.         small := "ABCD"; 
  4087.       the call 
  4088.         CanInsertAll(LENGTH("XYZ"), 2, small) 
  4089.       returns the value FALSE 
  4090.  
  4091.    2. small := "ABCD"; 
  4092.       Insert("XYZ", 2, small) 
  4093.       results in small having value "ABXYZ" without terminator 
  4094.  
  4095.    3. large := "ABC"; 
  4096.       IF CanInsertAll(3, 2, large) THEN 
  4097.         Insert("XYZ", 2, large) 
  4098.       END 
  4099.       results in large having value "ABXYZC" 
  4100.  
  4101.    4. large := "ABCD"; ch := "X"; 
  4102.       Insert(String1{ch}, 2, large) 
  4103.       results in large having value "ABXCD" 
  4104.  
  4105.  
  4106. ΓòÉΓòÉΓòÉ 6.1.10. CanReplaceAll - Check whether Replace will succeed ΓòÉΓòÉΓòÉ
  4107.  
  4108. PROCEDURE CanReplaceAll (sourceLength, startPos: CARDINAL;
  4109.                          VAR destination: ARRAY OF CHAR
  4110.                         ): BOOLEAN;
  4111.  
  4112. The function procedure CanReplaceAll returns is the value of the Boolean 
  4113. expression sourceLength + startPos <= LENGTH(destination) 
  4114.  
  4115. NOTES: 
  4116.  
  4117.      CanReplaceAll may be used to check whether complete replacement of a 
  4118.       substring value within a string variable will be possible using, for 
  4119.       example, the procedure Replace. 
  4120.  
  4121.      The preservation of the string abstraction is taken as the goal of the 
  4122.       string module. This means that the operation completion condition of 
  4123.       CanReplaceAll only tests whether the proposed replacement is valid within 
  4124.       the given string length; the procedure Replace always preserves the 
  4125.       length of its destination string. 
  4126.  
  4127.  
  4128. ΓòÉΓòÉΓòÉ 6.1.11. Replace - Replace substring ΓòÉΓòÉΓòÉ
  4129.  
  4130. PROCEDURE Replace (source: ARRAY OF CHAR;
  4131.                    startPos: CARDINAL;
  4132.                    VAR destination: ARRAY OF CHAR);
  4133.  
  4134. The procedure Replace modifies the string value from destination by overwriting 
  4135. characters in destination with characters extracted from the string value in 
  4136. source. Overwriting begins at the position given by startPos and continues as 
  4137. long as there are characters left to overwrite in destination and characters 
  4138. left to extract from source. The string value in destination is not altered if 
  4139. startPos is greater than or equal to LENGTH(destination). 
  4140.  
  4141. NOTE: 
  4142.  
  4143. The length of the string value in destination is always preserved by Replace. 
  4144.  
  4145. EXAMPLE - String replacement. 
  4146.  
  4147.    1. after the assignment 
  4148.         small := "ABC" 
  4149.       the call 
  4150.         CanReplaceAll(LENGTH("XY"), 2, small) 
  4151.       returns the value FALSE 
  4152.  
  4153.    2. small := "ABC"; 
  4154.       Replace("XY", 2, small) 
  4155.       results in small[0] having value "ABX" 
  4156.  
  4157.    3. large := "ABCDEF"; 
  4158.       IF CanReplaceAll(3, 2, large) 
  4159.       THEN 
  4160.         Replace("XYZ", 2, large) 
  4161.       END 
  4162.       results in large having value "ABXYZF" 
  4163.  
  4164.  
  4165. ΓòÉΓòÉΓòÉ 6.1.12. CanAppendAll - Check whether Append will succeed ΓòÉΓòÉΓòÉ
  4166.  
  4167. PROCEDURE CanAppendAll (sourceLength: CARDINAL;
  4168.                         VAR destination: ARRAY OF CHAR
  4169.                        ): BOOLEAN;
  4170.  
  4171. The function procedure CanAppendAll returns the value of the Boolean expression 
  4172. LENGTH(destination) + sourceLength <= HIGH(destination) + 1 
  4173.  
  4174. NOTE: 
  4175.  
  4176. CanAppendAll may be used to check whether it will be possible to append a 
  4177. string value to another string value held within a string variable using, for 
  4178. example, the procedure Append. 
  4179.  
  4180.  
  4181. ΓòÉΓòÉΓòÉ 6.1.13. Append - Append string ΓòÉΓòÉΓòÉ
  4182.  
  4183. PROCEDURE Append (source: ARRAY OF CHAR;
  4184.                   VAR destination: ARRAY OF CHAR);
  4185.  
  4186. The procedure Append creates a new string value by appending the string value 
  4187. in source onto destination. If the length of the created string value exceeds 
  4188. the capacity of destination, the string value is truncated to the capacity of 
  4189. destination, and the truncated value is assigned to destination. If the length 
  4190. of the created string value is less than the capacity of destination, a string 
  4191. terminator is appended to the string value, and the resulting value is assigned 
  4192. to destination. 
  4193.  
  4194. EXAMPLE - Appending to strings. 
  4195.  
  4196.    1. after the assignment 
  4197.         small := "pqr" 
  4198.       the call 
  4199.         CanAppendAll(LENGTH("XYZ"), small) 
  4200.       returns the value FALSE 
  4201.  
  4202.    2. small := "pqr"; 
  4203.       Append("XYZ", small) 
  4204.       results in small having value "pqrXY" without terminator 
  4205.  
  4206.    3. small := "pqr"; 
  4207.       ch := "s"; 
  4208.       Append(String1{ch}, small) 
  4209.       results in small having value "pqrs" 
  4210.  
  4211.  
  4212. ΓòÉΓòÉΓòÉ 6.1.14. CanConcatAll - Check whether Concat will succeed ΓòÉΓòÉΓòÉ
  4213.  
  4214. PROCEDURE CanConcatAll (source1Length, source2Length: CARDINAL;
  4215.                         VAR destination: ARRAY OF CHAR
  4216.                        ): BOOLEAN;
  4217.  
  4218. The function procedure CanConcatAll returns the value of the Boolean expression 
  4219. source1Length + source2Length <= HIGH(destination) + 1 
  4220.  
  4221. NOTE: 
  4222.  
  4223. CanConcatAll may be used to check whether complete concatenation of two string 
  4224. values will be possible within the capacity of a specified string variable 
  4225. using, for example, the procedure Concat. 
  4226.  
  4227.  
  4228. ΓòÉΓòÉΓòÉ 6.1.15. Concat - Concatenate strings ΓòÉΓòÉΓòÉ
  4229.  
  4230. PROCEDURE Concat (source1, source2: ARRAY OF CHAR;
  4231.                   VAR destination: ARRAY OF CHAR);
  4232.  
  4233. The procedure Concat creates a new string value by appending the substring 
  4234. value source2 onto source1. If the length of the created string value exceeds 
  4235. the capacity of destination, the string value is truncated to the capacity of 
  4236. destination, and the truncated value is assigned to destination. If the length 
  4237. of the created string value is less than the capacity of destination, a string 
  4238. terminator is appended to the string value, and the resulting value is assigned 
  4239. to destination. 
  4240.  
  4241. EXAMPLE - String concatenation. 
  4242.  
  4243.    1. after the assignment 
  4244.         small := "pqr" 
  4245.       the call 
  4246.         CanConcatAll(4, LENGTH(small), small) 
  4247.       returns the value FALSE 
  4248.  
  4249.    2. small := "pqr"; 
  4250.       Concat("WXYZ", small, small) 
  4251.       results in small having value "WXYZp" without terminator 
  4252.  
  4253.    3. small := "jk"; large := ""; 
  4254.       ch := "s"; 
  4255.       Concat(String1{ch}, small, large) 
  4256.       results in large having value "skj" 
  4257.  
  4258.  
  4259. ΓòÉΓòÉΓòÉ 6.1.16. Capitalize - Capitalize string ΓòÉΓòÉΓòÉ
  4260.  
  4261. PROCEDURE Capitalize (VAR stringVar: ARRAY OF CHAR);
  4262.  
  4263. The procedure Capitalize applies the standard function CAP to each character of 
  4264. the string value in stringVar. 
  4265.  
  4266. NOTE: 
  4267.  
  4268. Capitalize may be used to achieve case-insensitive use of the procedures 
  4269. Compare, FindNext, FindPrev and FindDiff. 
  4270.  
  4271. EXAMPLE - String capitalization. 
  4272.  
  4273. The following example assumes a capitalization mapping which maps p to P, q to 
  4274. Q and r to R. 
  4275.  
  4276.    1. small := "pqr"; 
  4277.       Capitalize(small) 
  4278.       results in small having value "PQR" 
  4279.  
  4280.  
  4281. ΓòÉΓòÉΓòÉ 6.1.17. Compare - Compare strings ΓòÉΓòÉΓòÉ
  4282.  
  4283. PROCEDURE Compare (stringVal1, stringVal2: ARRAY OF CHAR
  4284.                   ): CompareResults;
  4285.  
  4286. The function procedure Compare returns a value of the enumeration type 
  4287. CompareResults depending on the lexical ordering of the type CHAR. The value 
  4288. returned is less, equal or greater according as the string value in stringVal1 
  4289. is lexically less than, equal to, or greater than the string value in 
  4290. stringVal2. 
  4291.  
  4292. NOTES: 
  4293.  
  4294.      The result of this function is dependent upon the full collating sequence 
  4295.       of character values. This sequence is implementation-defined, although it 
  4296.       must have certain properties. 
  4297.  
  4298.      In general, the result of this function is case-sensitive. 
  4299.  
  4300.  EXAMPLE - String comparison. 
  4301.  
  4302.    1. Compare("", "") returns equal 
  4303.  
  4304.    2. Compare("", "abc") returns less 
  4305.  
  4306.    3. Compare("abc", "") returns greater 
  4307.  
  4308.    4. Compare("pqr", "pqr") returns equal 
  4309.  
  4310.    5. Compare("pqr", "pqrstuv") returns less 
  4311.  
  4312.    6. Compare("pqrstuv", "pqr") returns greater 
  4313.  
  4314.    7. Compare("abc", "pqr") returns less 
  4315.  
  4316.    8. Compare("pqr", "abc") returns greater 
  4317.  
  4318.    9. Compare("abcdef ", "p") returns less 
  4319.  
  4320.   10. Compare("p", "abcdef ") returns greater 
  4321.  
  4322.  
  4323. ΓòÉΓòÉΓòÉ 6.1.18. Equal - Compare strings ΓòÉΓòÉΓòÉ
  4324.  
  4325. PROCEDURE Equal (stringVal1, stringVal2: ARRAY OF CHAR): BOOLEAN;
  4326.  
  4327. The function procedure Equal returns the value of the Boolean expression 
  4328. Strings.Compare(stringVal1, stringVal2) = Strings.equal 
  4329.  
  4330.  
  4331. ΓòÉΓòÉΓòÉ 6.1.19. FindNext - Search string forward ΓòÉΓòÉΓòÉ
  4332.  
  4333. PROCEDURE FindNext (pattern, stringToSearch: ARRAY OF CHAR;
  4334.                     startPos: CARDINAL;
  4335.                     VAR patternFound: BOOLEAN;
  4336.                     VAR posOfPattern: CARDINAL);
  4337.  
  4338. The procedure FindNext searches forwards for the next occurrence of pattern in 
  4339. stringToSearch, starting the search in stringToSearch at position startPos. If 
  4340. pattern is found, the value TRUE is assigned to patternFound, and posOfPattern 
  4341. contains the starting position of pattern in stringToSearch; posOfPattern is in 
  4342. the range [startPos..LENGTH(stringToSearch)-1]. Otherwise the value FALSE is 
  4343. assigned to patternFound and posOfPattern is unchanged. 
  4344.  
  4345. NOTES: 
  4346.  
  4347.      The pattern might be found at the given value of startPos. 
  4348.  
  4349.      If startPos > LENGTH(stringToSearch) - LENGTH(pattern) then patternFound 
  4350.       is returned as FALSE. 
  4351.  
  4352.  EXAMPLE - Forwards string search. 
  4353.  
  4354.    1. large := "Hello hello hello"; 
  4355.       FindNext("ll", large, 0, found, pos) 
  4356.       results in: 
  4357.       found having value TRUE 
  4358.       pos having value 2 
  4359.  
  4360.    2. large := "Hello hello hello"; 
  4361.       FindNext("ll", large, 0, found, pos); 
  4362.       FindNext("ll", large, pos+1, found, pos) 
  4363.       results in: 
  4364.       found having value TRUE 
  4365.       pos having value 8 
  4366.  
  4367.    3. large := "abcdefghijklmnopqrstuvwxyz"; 
  4368.       ch := "x"; 
  4369.       FindNext(String1fchg, large, 0, found, pos) 
  4370.       results in: 
  4371.       found having value TRUE 
  4372.       pos having value 23 
  4373.  
  4374.    4. large := "abcdefghijklmnopqrstuvwxyz"; 
  4375.       ch := "x"; 
  4376.       FindNext(String1fchg, large, 26, found, pos) 
  4377.       results in: 
  4378.       found having value FALSE 
  4379.       pos remains unchanged 
  4380.  
  4381.  
  4382. ΓòÉΓòÉΓòÉ 6.1.20. FindPrev - Search string backward ΓòÉΓòÉΓòÉ
  4383.  
  4384. PROCEDURE FindPrev (pattern, stringToSearch: ARRAY OF CHAR;
  4385.                     startPos: CARDINAL;
  4386.                     VAR patternFound: BOOLEAN;
  4387.                     VAR posOfPattern: CARDINAL);
  4388.  
  4389. The procedure FindPrev looks backwards for an occurrence of pattern in the 
  4390. string value in stringToSearch, starting the search in stringToSearch at 
  4391. position startPos. If pattern is found, the value TRUE is assigned to 
  4392. patternFound, and posOfPattern contains the starting position of pattern in 
  4393. stringToSearch; posOfPattern is in the range [0..startPos]. Otherwise the value 
  4394. FALSE is assigned to patternFound and posOfPattern is unchanged. 
  4395.  
  4396. NOTES: 
  4397.  
  4398.      The pattern might be found at the given value of startPos. 
  4399.  
  4400.      If startPos > LENGTH(stringToSearch)-LENGTH(pattern) the whole string 
  4401.       value is searched. 
  4402.  
  4403.  EXAMPLE - Backwards string search. 
  4404.  
  4405.    1. large := "aabbbcccc"; 
  4406.       FindPrev("cc", large, 200, found, pos) 
  4407.       results in: 
  4408.       found having value TRUE 
  4409.       pos having value 7 
  4410.  
  4411.    2. large := "aabbbcccc"; 
  4412.       FindPrev("cc", large, 200, found, pos); 
  4413.       FindPrev("cc", large, pos-1, found, pos) 
  4414.       results in: 
  4415.       found having value TRUE 
  4416.       pos having value 6 
  4417.  
  4418.    3. large := "Maybe this makes sense"; 
  4419.       FindPrev("se", large, 200, found, pos) 
  4420.       results in: 
  4421.       found having value TRUE 
  4422.       pos having value 20 
  4423.  
  4424.    4. large := "Maybe this makes sense"; 
  4425.       FindPrev("se", large, 20, found, pos); 
  4426.       FindPrev("se", large, pos-1, found, pos) 
  4427.       results in: 
  4428.       found having value TRUE 
  4429.       pos having value 17 
  4430.  
  4431.  
  4432. ΓòÉΓòÉΓòÉ 6.1.21. FindDiff - Find position of string difference ΓòÉΓòÉΓòÉ
  4433.  
  4434. PROCEDURE FindDiff (stringVal1, stringVal2: ARRAY OF CHAR;
  4435.                     VAR differenceFound: BOOLEAN;
  4436.                     VAR posOfDifference: CARDINAL);
  4437.  
  4438. The procedure FindDiff compares the string values in stringVal1 and stringVal2. 
  4439. The value FALSE is assigned to differenceFound if the string values are equal 
  4440. and TRUE otherwise. If differenceFound is TRUE, the position of the first 
  4441. difference between the string values is assigned to posOfDifference; otherwise 
  4442. posOfDifference is unchanged. 
  4443. Examples 
  4444.  
  4445.  - Finding string differences. 
  4446.  
  4447.    1. FindDiff("", "", areDiff, pos) results in: 
  4448.       areDiff having value FALSE 
  4449.       pos being unchanged 
  4450.  
  4451.    2. FindDiff("abc", "", areDiff, pos) results in: 
  4452.       areDiff having value TRUE 
  4453.       pos having value 0 
  4454.  
  4455.    3. FindDiff("", "abc", areDiff, pos) results in: 
  4456.       areDiff having value TRUE pos having value 0 
  4457.  
  4458.    4. FindDiff("pqr", "pqt", areDiff, pos) results in: 
  4459.       areDiff having value TRUE 
  4460.       pos having value 2 
  4461.  
  4462.    5. FindDiff("pqr", "pqrstuv", areDiff, pos) results in: 
  4463.       areDiff having value TRUE 
  4464.       pos having value 3 
  4465.  
  4466.    6. FindDiff("pqrstuv", "pqr", areDiff, pos) results in: 
  4467.       areDiff having value TRUE 
  4468.       pos having value 3 
  4469.  
  4470.  
  4471. ΓòÉΓòÉΓòÉ 7. String Conversions ΓòÉΓòÉΓòÉ
  4472.  
  4473. The string conversions library allows the conversion of the values of numeric 
  4474. data types to and from character string representations. The modules WholeStr, 
  4475. RealStr, and LongStr provide simple high-level facilities for converting to and 
  4476. from strings and whole number and real number data types. Low-level facilities 
  4477. are provided by the corresponding modules WholeConv, RealConv, and LongConv. 
  4478. Common data types and values that are used in the definition modules are 
  4479. defined by the module ConvTypes. 
  4480.  
  4481. The formats for string conversions correspond to those for numeric input and 
  4482. output, except that the numeric output routines provide for (right) alignment 
  4483. in a specified field width | see 9.2.2.2 and 9.2.2.3. 
  4484.  
  4485.      Common Data Types 
  4486.      High-Level String Conversion Modules 
  4487.      Low-Level String Conversion Modules 
  4488.  
  4489.  
  4490. ΓòÉΓòÉΓòÉ 7.1. Common Data Types ΓòÉΓòÉΓòÉ
  4491.  
  4492. The module ConvTypes defines types and values that are used in the high-level 
  4493. and low-level string conversion definition modules. Where appropriate, the 
  4494. conversion modules define types in terms of those defined in ConvTypes. Direct 
  4495. import from this module is not normally necessary in modules that are clients 
  4496. of the high-level conversion modules. 
  4497.  
  4498.      Module ConvTypes 
  4499.  
  4500.  
  4501. ΓòÉΓòÉΓòÉ 7.1.1. Module ConvTypes ΓòÉΓòÉΓòÉ
  4502.  
  4503. The module ConvTypes defines the enumeration type ConvResults with values for 
  4504. expressing the format of strings that are interpreted as representing values of 
  4505. numeric data types. The module also defines the types ScanClass and ScanState, 
  4506. which the low-level conversion modules use in the definition of procedures that 
  4507. control lexical scanning. 
  4508.  
  4509. TYPE
  4510.   ConvResults =     (* Values of this type are used
  4511.                        to express the format of a string: *)
  4512.   (
  4513.     strAllRight,    (* the string format is correct
  4514.                        for the corresponding conversion *)
  4515.     strOutOfRange,  (* the string is well-formed but the value
  4516.                        cannot be represented *)
  4517.     strWrongFormat, (* the string is in the wrong format
  4518.                        for the conversion *)
  4519.     strEmpty        (* the given string is empty *)
  4520.   );
  4521.  
  4522.   ScanClass =  (* Values of this type are used to classify input
  4523.                   to finite state scanners: *)
  4524.   (
  4525.     padding,   (* a leading or padding character at this point
  4526.                   in the scan - ignore it *)
  4527.     valid,     (* a valid character at this point
  4528.                   in the scan - accept it *)
  4529.     invalid,   (* an invalid character at this point
  4530.                   in the scan - reject it *)
  4531.     terminator (* a terminating character at this point
  4532.                   in the scan (not part of token) *)
  4533.   );
  4534.  
  4535.   ScanState = (* The type of lexical scanning
  4536.                  control procedures *)
  4537.    PROCEDURE (CHAR, VAR ScanClass, VAR ScanState);
  4538.  
  4539.  
  4540. ΓòÉΓòÉΓòÉ 7.2. High-Level String Conversion Modules ΓòÉΓòÉΓòÉ
  4541.  
  4542. Separate high-level string conversion modules are defined for the whole number 
  4543. types (INTEGER and CARDINAL), and for the real number types (REAL and 
  4544. LONGREAL). These all use decimal notation. 
  4545.  
  4546. In calls of procedures converting from strings, the source parameter str is 
  4547. assumed to contain a string value (which is terminated by the string terminator 
  4548. character if the length of the string is less than the capacity of the array). 
  4549. While leading spaces are ignored, the entire remainder of the string has to be 
  4550. in the correct format for the conversion to take place. 
  4551.  
  4552. In calls of procedures converting to strings, the destination parameter str is 
  4553. assigned a string value (which is terminated by the string terminator character 
  4554. if the length of the string is less than the capacity of the array). If the 
  4555. destination parameter is of insufficient capacity, the string is truncated. 
  4556. Users may determine whether truncation will occur by using procedures such as 
  4557. LengthCard from the low-level string conversion modules | see 9.5.3.1.2. 
  4558.  
  4559. NOTE: 
  4560.  
  4561. The string conversion procedures may be used with strings read by 
  4562. STextIO.ReadToken or TextIO.ReadToken, if it is required that entire 
  4563. space-character delimited tokens are in the correct format | see 9.2.2.1.2. 
  4564.  
  4565. High-Level String Conversion Modules 
  4566.  
  4567. [htbp] EXAMPLE - Conversion of strings read by ReadToken 
  4568.  
  4569. This example shows how space-character delimited tokens that cannot be 
  4570. converted to values of type CARDINAL can be replaced by descriptive text: 
  4571.  
  4572. firstOnLine := TRUE;
  4573. STextIO.ReadToken(inStr);
  4574. WHILE SIOResult.ReadResult() <> SIOResult.endOfInput DO
  4575.   WholeStr.StrToCard(inStr, inCard, inRes);
  4576.   CASE inRes OF
  4577.   | ConvTypes.strAllRight .. ConvTypes.strWrongFormat:
  4578.      IF firstOnLine THEN
  4579.         firstOnLine := FALSE
  4580.      ELSE
  4581.         STextIO.WriteString(" ")
  4582.      END
  4583.   | ConvTypes.strEmpty:
  4584.   firstOnLine := TRUE;
  4585.   STextIO.SkipLine
  4586.   END;
  4587.   CASE inRes OF
  4588.   | ConvTypes.strAllRight:
  4589.      STextIO.WriteString(inStr)
  4590.   | ConvTypes.strOutOfRange:
  4591.      STextIO.WriteString("out-of-range")
  4592.   | ConvTypes.strWrongFormat:
  4593.      STextIO.WriteString("wrong-format")
  4594.   | ConvTypes.strEmpty:
  4595.      STextIO.WriteLn
  4596.   END;
  4597.   STextIO.ReadToken(inStr)
  4598. END;
  4599.  
  4600. It is assumed here that the capacity of the character array variable inStr is 
  4601. sufficient to accommodate the longest token in the input stream. 
  4602.  
  4603.      Module WholeStr 
  4604.      Modules RealStr and LongStr 
  4605.  
  4606.  
  4607. ΓòÉΓòÉΓòÉ 7.2.1. Module WholeStr ΓòÉΓòÉΓòÉ
  4608.  
  4609. The module WholeStr provides procedures for the conversion of values of the 
  4610. type INTEGER and the type CARDINAL to and from strings. 
  4611.  
  4612. The string form of a signed whole number is 
  4613.  
  4614. ["+" | "-"], decimal digit, {decimal digit}
  4615.  
  4616. The string form of an unsigned whole number is 
  4617.  
  4618. decimal digit, {decimal digit}
  4619.  
  4620.      StrToInt - Convert string to INTEGER 
  4621.      IntToStr - Convert INTEGER to string 
  4622.      StrToCard - Convert string to CARDINAL 
  4623.      CardToStr - Convert CARDINAL to string 
  4624.  
  4625.  
  4626. ΓòÉΓòÉΓòÉ 7.2.1.1. StrToInt - Convert string to INTEGER ΓòÉΓòÉΓòÉ
  4627.  
  4628. PROCEDURE StrToInt (str: ARRAY OF CHAR;
  4629.                     VAR int: INTEGER;
  4630.                     VAR res: ConvResults);
  4631.  
  4632. Module WholeStr 
  4633.  
  4634. The procedure StrToInt ignores leading spaces in str and assigns values to int 
  4635. and res as follows: 
  4636.  
  4637.  strAllRight if the remainder of str represents a complete signed whole number 
  4638.            in the range of the type INTEGER; the value of this number is 
  4639.            assigned to int; 
  4640.  
  4641.  strOutOfRange if the remainder of str represents a complete signed whole 
  4642.            number but its value is out of the range of the type INTEGER; the 
  4643.            value MAX(INTEGER) or MIN(INTEGER) is assigned to int according to 
  4644.            the sign of the number; 
  4645.  
  4646.  strWrongFormat if there are remaining characters in str but these are not in 
  4647.            the form of a complete signed whole number; the value of int is not 
  4648.            defined; 
  4649.  
  4650.  strEmpty  if there are no remaining characters in str | the value of int is 
  4651.            not defined. 
  4652.  
  4653.  
  4654. ΓòÉΓòÉΓòÉ 7.2.1.2. IntToStr - Convert INTEGER to string ΓòÉΓòÉΓòÉ
  4655.  
  4656. PROCEDURE IntToStr (int: INTEGER; VAR str: ARRAY OF CHAR);
  4657.  
  4658. Module WholeStr 
  4659.  
  4660. The procedure IntToStr assigns to str the possibly truncated string 
  4661. corresponding to the value of int. A sign is included only for negative values. 
  4662.  
  4663.  
  4664. ΓòÉΓòÉΓòÉ 7.2.1.3. StrToCard - Convert string to CARDINAL ΓòÉΓòÉΓòÉ
  4665.  
  4666. PROCEDURE StrToCard (str: ARRAY OF CHAR;
  4667.                      VAR card: CARDINAL;
  4668.                      VAR res: ConvResults);
  4669.  
  4670. Module WholeStr 
  4671.  
  4672. The procedure StrToCard ignores leading spaces in str and assigns values to 
  4673. card and res as follows: 
  4674.  
  4675.  strAllRight if the remainder of str represents a complete unsigned whole 
  4676.            number in the range of the type CARDINAL; the value of this number 
  4677.            is assigned to card; 
  4678.  
  4679.  strOutOfRange if the remainder of str represents a complete unsigned whole 
  4680.            number but its value is out of the range of the type CARDINAL; the 
  4681.            value MAX(CARDINAL) is assigned to card; 
  4682.  
  4683.  strWrongFormat if there are remaining characters in str but these are not in 
  4684.            the form of a complete unsigned whole number; the value of card is 
  4685.            not defined; 
  4686.  
  4687.  strEmpty  if there are no remaining characters in str; the value of card is 
  4688.            not defined. 
  4689.  
  4690.  
  4691. ΓòÉΓòÉΓòÉ 7.2.1.4. CardToStr - Convert CARDINAL to string ΓòÉΓòÉΓòÉ
  4692.  
  4693. PROCEDURE CardToStr (card: CARDINAL; VAR str: ARRAY OF CHAR);
  4694.  
  4695. Module WholeStr 
  4696.  
  4697. The procedure CardToStr assigns to str the possibly truncated string 
  4698. corresponding to the value of card. 
  4699.  
  4700.  
  4701. ΓòÉΓòÉΓòÉ 7.2.2. Modules RealStr and LongStr ΓòÉΓòÉΓòÉ
  4702.  
  4703. The modules RealStr and LongStr provide procedures for the conversion of real 
  4704. numbers to and from strings. In the case of RealStr, real number parameters are 
  4705. of the type REAL. In the case of LongStr, real number parameters are of the 
  4706. type LONGREAL. 
  4707.  
  4708. The semantics of the two modules is the same, except that when module RealStr 
  4709. refers to the pervasive type REAL, the corresponding procedure in LongStr 
  4710. refers to the pervasive type LONGREAL. 
  4711.  
  4712. NOTE: 
  4713.  
  4714. The above statement is merely to avoid needless repetition of the semantics for 
  4715. LongStr. 
  4716.  
  4717. The string form of a signed fixed-point real number is 
  4718.  
  4719. ["+" | "-"], decimal digit, {decimal digit},
  4720. [".", {decimal digit}]
  4721.  
  4722. The string form of a signed floating-point real number is 
  4723.  
  4724. signed fixed-point real number,
  4725. "E"|"e", ["+" | "-"], decimal digit, {decimal digit}
  4726.  
  4727.      StrToReal - Convert string to real 
  4728.      RealToFloat - Convert real to string (float notation) 
  4729.      RealToEng - Convert real to string (eng. notation) 
  4730.      RealToFixed - Convert real to string (fixed notation) 
  4731.      RealToStr - Convert real to string (auto notation) 
  4732.  
  4733.  
  4734. ΓòÉΓòÉΓòÉ 7.2.2.1. StrToReal - Convert string to real ΓòÉΓòÉΓòÉ
  4735.  
  4736. PROCEDURE StrToReal (str: ARRAY OF CHAR;
  4737.                      VAR real: REAL;
  4738.                      VAR res: ConvResults);
  4739. PROCEDURE StrToReal (str: ARRAY OF CHAR;
  4740.                      VAR real: LONGREAL;
  4741.                      VAR res: ConvResults);
  4742.  
  4743. Modules: RealStr, LongStr 
  4744.  
  4745. The procedure StrToReal ignores leading spaces in str and assigns values to res 
  4746. and real as follows: 
  4747.  
  4748.  strAllRight if the remainder of str represents a complete signed real number 
  4749.            in the range of the type of real; the value of this number is 
  4750.            assigned to real; 
  4751.  
  4752.  strOutOfRange if the remainder of str represents a complete signed real number 
  4753.            but its value is out of the range of the type of real; the maximum 
  4754.            or minimum value of the type of real is assigned to real according 
  4755.            to the sign of the number; 
  4756.  
  4757.  strWrongFormat if there are remaining characters in str but these are not in 
  4758.            the form of a complete signed real number; the value of real is not 
  4759.            defined; 
  4760.  
  4761.  strEmpty  if there are no remaining characters in str; the value of real is 
  4762.            not defined. 
  4763.  
  4764.  
  4765. ΓòÉΓòÉΓòÉ 7.2.2.2. RealToFloat - Convert real to string (float notation) ΓòÉΓòÉΓòÉ
  4766.  
  4767. PROCEDURE RealToFloat (real: REAL;
  4768.                        sigFigs: CARDINAL;
  4769.                        VAR str: ARRAY OF CHAR);
  4770. PROCEDURE RealToFloat (real: LONGREAL;
  4771.                        sigFigs: CARDINAL;
  4772.                        VAR str: ARRAY OF CHAR);
  4773.  
  4774. Modules: RealStr, LongStr 
  4775.  
  4776. The procedure RealToFloat assigns to str the possibly truncated string 
  4777. corresponding to the value of real in floating-point form. A sign is included 
  4778. only for negative values. One significant digit is included in the whole number 
  4779. part. The signed exponent part is included only if the exponent value is not 0. 
  4780. If the value of sigFigs is greater than 0, that number of significant digits is 
  4781. included, otherwise an implementation-defined number of significant digits is 
  4782. included. The decimal point is not included if there are no significant digits 
  4783. in the fractional part. 
  4784.  
  4785.  
  4786. ΓòÉΓòÉΓòÉ 7.2.2.3. RealToEng - Convert real to string (eng. notation) ΓòÉΓòÉΓòÉ
  4787.  
  4788. PROCEDURE RealToEng (real: REAL;
  4789.                      sigFigs: CARDINAL;
  4790.                      VAR str: ARRAY OF CHAR);
  4791. PROCEDURE RealToEng (real: LONGREAL;
  4792.                      sigFigs: CARDINAL;
  4793.                      VAR str: ARRAY OF CHAR);
  4794.  
  4795. Modules: RealStr, LongStr 
  4796.  
  4797. The procedure RealToEng behaves like the procedure RealToFloat except that the 
  4798. number is scaled with one to three digits in the whole number part and with an 
  4799. exponent that is a multiple of three. 
  4800.  
  4801.  
  4802. ΓòÉΓòÉΓòÉ 7.2.2.4. RealToFixed - Convert real to string (fixed notation) ΓòÉΓòÉΓòÉ
  4803.  
  4804. PROCEDURE RealToFixed (real: REAL;
  4805.                        place: INTEGER;
  4806.                        VAR str: ARRAY OF CHAR);
  4807. PROCEDURE RealToFixed (real: LONGREAL;
  4808.                        place: INTEGER;
  4809.                        VAR str: ARRAY OF CHAR);
  4810.  
  4811. Modules: RealStr, LongStr 
  4812.  
  4813. The procedure RealToFixed assigns to str the possibly truncated string 
  4814. corresponding to the value of real in fixed-point form. A sign is included only 
  4815. for negative values. At least one digit is included in the whole number part. 
  4816. The value is rounded to the given value of place relative to the decimal point. 
  4817. The decimal point is suppressed if place is less than 0. 
  4818.  
  4819.  
  4820. ΓòÉΓòÉΓòÉ 7.2.2.5. RealToStr - Convert real to string (auto notation) ΓòÉΓòÉΓòÉ
  4821.  
  4822. PROCEDURE RealToStr (real: REAL; VAR str: ARRAY OF CHAR);
  4823. PROCEDURE RealToStr (real: LONGREAL; VAR str: ARRAY OF CHAR);
  4824.  
  4825. Modules: RealStr, LongStr 
  4826.  
  4827. If the sign and magnitude of real can be shown within the capacity of str, the 
  4828. call RealToStr(real,str) behaves like the call RealToFixed(real,place,str), 
  4829. with a value of place chosen to fill exactly the remainder of str. Otherwise, 
  4830. the call behaves as the call RealToFloat(real,sigFigs,str), with a value of 
  4831. sigFigs of at least one, but otherwise limited to the number of significant 
  4832. digits that can be included together with the sign and exponent part in str. 
  4833.  
  4834.  
  4835. ΓòÉΓòÉΓòÉ 7.3. Low-Level String Conversion Modules ΓòÉΓòÉΓòÉ
  4836.  
  4837. Separate low-level string conversion modules are defined for the whole number 
  4838. types (INTEGER and CARDINAL), and for the real number types (REAL and 
  4839. LONGREAL). These all use decimal notation. 
  4840.  
  4841. Procedures are defined to return the length of the string that is required to 
  4842. represent a given value, to return the format of a given string, to return the 
  4843. value of a string known to be in the correct format for conversion, and to 
  4844. allow control of lexical scanning of character sequences. 
  4845.  
  4846. NOTE: 
  4847.  
  4848. The types designated by ConvTypes.ScanClass and ConvTypes.ScanState are not 
  4849. given aliases in the low-level conversion modules. This is because clients of a 
  4850. separate finite state interpreter module need to refer only to procedures such 
  4851. as WholeConv.ScanInt, which represent the start state, and not to the types 
  4852. themselves. 
  4853.  
  4854.      Module WholeConv 
  4855.      Modules RealConv and LongConv 
  4856.  
  4857.  
  4858. ΓòÉΓòÉΓòÉ 7.3.1. Module WholeConv ΓòÉΓòÉΓòÉ
  4859.  
  4860. The module WholeConv provides low-level string conversion procedures for values 
  4861. of the type INTEGER and values of the type CARDINAL. 
  4862.  
  4863.      ScanInt - Scan one character of INTEGER 
  4864.      FormatInt - Query INTEGER format 
  4865.      ValueInt - Query INTEGER value 
  4866.      LengthInt - Query INTEGER length 
  4867.      ScanCard - Scan one character of CARDINAL 
  4868.      FormatCard - Query CARDINAL format 
  4869.      ValueCard - Query CARDINAL value 
  4870.      LengthCard - Query CARDINAL length 
  4871.      IsWholeConvException - Query exceptional state 
  4872.  
  4873.  
  4874. ΓòÉΓòÉΓòÉ 7.3.1.1. ScanInt - Scan one character of INTEGER ΓòÉΓòÉΓòÉ
  4875.  
  4876. PROCEDURE ScanInt (inputCh: CHAR;
  4877.                    VAR chClass: ConvTypes.ScanClass;
  4878.                    VAR nextState: ConvTypes.ScanState);
  4879.  
  4880. Module WholeConv 
  4881.  
  4882. The procedure ScanInt assigns values to chClass and nextState depending upon 
  4883. the value of inputCh as shown in the following table: 
  4884.  
  4885. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  4886.  Procedure  inputCh        chClass     nextState
  4887.  
  4888.                                        a procedure with
  4889.  
  4890.                                        behaviour of
  4891.  
  4892.  ScanInt    space          padding     ScanInt
  4893.  
  4894.             sign           valid       S
  4895.  
  4896.             decimal digit  valid       W
  4897.  
  4898.             other          invalid     ScanInt
  4899.  
  4900.  S          decimal digit  valid       W
  4901.  
  4902.             other          invalid     S
  4903.  
  4904.  W          decimal digit  valid       W
  4905.  
  4906.             other          terminator  |
  4907. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  4908.  
  4909. NOTE: 
  4910.  
  4911. The procedure ScanInt corresponds to the start state of a finite state machine 
  4912. to scan for a character sequence that forms a signed whole number. Like 
  4913. ScanCard and the corresponding procedures in the other low-level string 
  4914. conversion modules, it may be used to control the actions of a finite state 
  4915. interpreter. As long as the value of chClass is other than terminator or 
  4916. invalid, the interpreter should call the procedure whose value is assigned to 
  4917. nextState by the previous call, supplying the next character from the sequence 
  4918. to be scanned. It may be appropriate for the interpreter to ignore characters 
  4919. classified as invalid, and proceed with the scan. This would be the case, for 
  4920. example, with interactive input, if only valid characters are being echoed in 
  4921. order to give interactive users an immediate indication of badly-formed data. 
  4922. If the character sequence ends before one is classified as terminator, the 
  4923. string-terminator character should be supplied as input to the finite state 
  4924. scanner. If the preceding character sequence formed a complete number, the 
  4925. string-terminator is classified as terminator, otherwise it is classified as 
  4926. invalid. 
  4927.  
  4928. ScanInt - Scan one character of INTEGER 
  4929.  
  4930. [htbp] EXAMPLE - Use of ScanInt 
  4931.  
  4932. The following procedure uses ScanInt to locate the position of the first 
  4933. character in a string that follows any leading spaces and to locate the 
  4934. position of the first character that is not part of an integer. These positions 
  4935. will coincide if the string does not contain an integer after any leading 
  4936. spaces, and will be equal to the string length if no such character is 
  4937. contained in the string. 
  4938.  
  4939. PROCEDURE FindInt(str: ARRAY OF CHAR; VAR first, next: CARDINAL);
  4940. VAR
  4941.   ch: CHAR;
  4942.   len, index: CARDINAL;
  4943.   state: ConvTypes.ConvState;
  4944.   class: ConvTypes.ConvClass;
  4945. BEGIN
  4946.   len := LENGTH(str);
  4947.   index := 0;
  4948.   first := len;
  4949.   state := WholeConv.ScanInt;
  4950.   LOOP
  4951.     IF index = len THEN EXIT END;
  4952.     state(str[index], class, state);
  4953.     CASE class OF
  4954.     | ConvTypes.padding:
  4955.     | ConvTypes.valid:
  4956.       IF index < first THEN first := index END;
  4957.     | ConvTypes.invalid, ConvTypes.terminator:
  4958.       EXIT
  4959.     END;
  4960.     INC(index)
  4961.   END;
  4962.   next := index
  4963. END FindInt;
  4964.  
  4965.  
  4966. ΓòÉΓòÉΓòÉ 7.3.1.2. FormatInt - Query INTEGER format ΓòÉΓòÉΓòÉ
  4967.  
  4968. PROCEDURE FormatInt (str: ARRAY OF CHAR): ConvResults;
  4969.  
  4970. Module WholeConv 
  4971.  
  4972. The function procedure FormatInt queries the format of str and returns: 
  4973.  
  4974.  strAllRight if str has a value representing a complete signed whole number 
  4975.            that is in the range of the type INTEGER; 
  4976.  
  4977.  strOutOfRange if str has a value representing a complete signed whole number 
  4978.            that is not in the range of INTEGER; 
  4979.  
  4980.  strWrongFormat if str has a value with remaining characters that do not form a 
  4981.            complete signed whole number; 
  4982.  
  4983.  strEmpty  if str has a value with no remaining characters; 
  4984.  
  4985.  FormatInt ignores any leading space characters in str. 
  4986.  
  4987.  
  4988. ΓòÉΓòÉΓòÉ 7.3.1.3. ValueInt - Query INTEGER value ΓòÉΓòÉΓòÉ
  4989.  
  4990. PROCEDURE ValueInt (str: ARRAY OF CHAR): INTEGER;
  4991.  
  4992. Module WholeConv 
  4993.  
  4994. If str has a value representing a signed whole number, the function procedure 
  4995. ValueInt returns the INTEGER value that corresponds to that number. Otherwise, 
  4996. the WholeConv exception is raised. 
  4997.  
  4998.  
  4999. ΓòÉΓòÉΓòÉ 7.3.1.4. LengthInt - Query INTEGER length ΓòÉΓòÉΓòÉ
  5000.  
  5001. PROCEDURE LengthInt (int: INTEGER): CARDINAL;
  5002.  
  5003. Module WholeConv 
  5004.  
  5005. The function procedure LengthInt returns the number of characters in the string 
  5006. representation of the value of int. 
  5007.  
  5008. NOTE: 
  5009.  
  5010. This value corresponds to the capacity of an array str which is of the minimum 
  5011. capacity needed to avoid truncation of the result in the call 
  5012. WholeStr.IntToStr(int,str). 
  5013.  
  5014.  
  5015. ΓòÉΓòÉΓòÉ 7.3.1.5. ScanCard - Scan one character of CARDINAL ΓòÉΓòÉΓòÉ
  5016.  
  5017. PROCEDURE ScanCard (inputCh: CHAR;
  5018.                     VAR chClass: ConvTypes.ScanClass;
  5019.                     VAR nextState: ConvTypes.ScanState);
  5020.  
  5021. Module WholeConv 
  5022.  
  5023. The procedure ScanCard assigns values to chClass and nextState depending upon 
  5024. the value of inputCh as shown in the following table: 
  5025.  
  5026. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  5027.  Procedure  inputCh        chClass     nextState
  5028.  
  5029.                                        a procedure with
  5030.  
  5031.                                        behaviour of
  5032.  
  5033.  ScanCard   space          padding     ScanCard
  5034.  
  5035.             decimal digit  valid       W
  5036.  
  5037.             other          invalid     ScanCard
  5038.  
  5039.  W          decimal digit  valid       W
  5040.  
  5041.             other          terminator  |
  5042. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  5043.  
  5044.  
  5045. ΓòÉΓòÉΓòÉ 7.3.1.6. FormatCard - Query CARDINAL format ΓòÉΓòÉΓòÉ
  5046.  
  5047. PROCEDURE FormatCard (str: ARRAY OF CHAR): ConvResults;
  5048.  
  5049. Module WholeConv 
  5050.  
  5051. The function procedure FormatCard queries the format of str and returns: 
  5052.  
  5053.  strAllRight if str has a value representing a complete unsigned whole number 
  5054.            that is in the range of the type CARDINAL; 
  5055.  
  5056.  strOutOfRange if str has a value representing a complete unsigned whole number 
  5057.            that is not in the range of CARDINAL; 
  5058.  
  5059.  strWrongFormat if str has a value with remaining characters that do not form a 
  5060.            complete unsigned whole number; 
  5061.  
  5062.  strEmpty  if str has a value with no remaining characters; 
  5063.  
  5064.  FormatCard ignores any leading space characters in str. 
  5065.  
  5066.  
  5067. ΓòÉΓòÉΓòÉ 7.3.1.7. ValueCard - Query CARDINAL value ΓòÉΓòÉΓòÉ
  5068.  
  5069. PROCEDURE ValueCard (str: ARRAY OF CHAR): CARDINAL;
  5070.  
  5071. Module WholeConv 
  5072.  
  5073. If str has a value representing an unsigned whole number, the function 
  5074. procedure ValueCard returns the CARDINAL value that corresponds to that number. 
  5075. Otherwise, the WholeConv exception is raised. 
  5076.  
  5077.  
  5078. ΓòÉΓòÉΓòÉ 7.3.1.8. LengthCard - Query CARDINAL length ΓòÉΓòÉΓòÉ
  5079.  
  5080. PROCEDURE LengthCard (card: CARDINAL): CARDINAL;
  5081.  
  5082. Module WholeConv 
  5083.  
  5084. The function procedure LengthCard returns the number of characters in the 
  5085. string representation of the value of card. 
  5086.  
  5087. NOTE: 
  5088.  
  5089. This value corresponds to the capacity of an array str which is of the minimum 
  5090. capacity needed to avoid truncation of the result in the call 
  5091. WholeStr.CardToStr(card,str). 
  5092.  
  5093.  
  5094. ΓòÉΓòÉΓòÉ 7.3.1.9. IsWholeConvException - Query exceptional state ΓòÉΓòÉΓòÉ
  5095.  
  5096. PROCEDURE IsWholeConvException (): BOOLEAN;
  5097.  
  5098. Module WholeConv 
  5099.  
  5100. The function procedure IsWholeConvException returns TRUE if the calling 
  5101. coroutine is in the state of exceptional execution because of the raising of 
  5102. the WholeConv exception, and FALSE otherwise. 
  5103.  
  5104.  
  5105. ΓòÉΓòÉΓòÉ 7.3.2. Modules RealConv and LongConv ΓòÉΓòÉΓòÉ
  5106.  
  5107. The modules RealConv and LongConv provide low-level string conversion 
  5108. procedures for values of the type REAL and values of the type LONGREAL. In the 
  5109. case of RealConv, real number parameters are of the type REAL. In the case of 
  5110. LongConv, real number parameters are of the type LONGREAL. 
  5111.  
  5112. The semantics of the two modules are the same, except that when module RealConv 
  5113. refers to the pervasive type REAL, the corresponding procedure in LongConv 
  5114. refers to the pervasive type LONGREAL. 
  5115.  
  5116. NOTE: 
  5117.  
  5118. The above statement is merely to avoid needless repetition of the semantics for 
  5119. LongConv. 
  5120.  
  5121.      ScanReal - Scan one character of real 
  5122.      FormatReal - Query real format 
  5123.      ValueReal - Query real value 
  5124.      LengthFloatReal - Query float length 
  5125.      LengthEngReal - Query engineering length 
  5126.      LengthFixedReal - Query fixed length 
  5127.      IsRConvException - Query exceptional state 
  5128.  
  5129.  
  5130. ΓòÉΓòÉΓòÉ 7.3.2.1. ScanReal - Scan one character of real ΓòÉΓòÉΓòÉ
  5131.  
  5132. PROCEDURE ScanReal (inputCh: CHAR;
  5133.                     VAR chClass: ConvTypes.ScanClass;
  5134.                     VAR nextState: ConvTypes.ScanState);
  5135. PROCEDURE ScanReal (inputCh: CHAR;
  5136.                     VAR chClass: ConvTypes.ScanClass;
  5137.                     VAR nextState: ConvTypes.ScanState);
  5138.  
  5139. Modules: RealConv, LongConv 
  5140.  
  5141. The procedure ScanReal assigns values to chClass and nextState depending upon 
  5142. the value of inputCh as shown in the following table: 
  5143.  
  5144. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  5145.  Procedure  inputCh        chClass     nextState
  5146.  
  5147.                                        a procedure with
  5148.  
  5149.                                        behaviour of
  5150.  
  5151.  ScanReal   space          padding     ScanReal
  5152.  
  5153.             sign           valid       RS
  5154.  
  5155.             decimal digit  valid       P
  5156.  
  5157.             other          invalid     ScanReal
  5158.  
  5159.  RS         decimal digit  valid       P
  5160.  
  5161.             other          invalid     RS
  5162.  
  5163.  P          decimal digit  valid       P
  5164.  
  5165.             "."            valid       F
  5166.  
  5167.             "E"            valid       E
  5168.  
  5169.             other          terminator  |
  5170.  
  5171.  F          decimal digit  valid       F
  5172.  
  5173.             "E"            valid       E
  5174.  
  5175.             other          terminator  |
  5176.  
  5177.  E          sign           valid       SE
  5178.  
  5179.             decimal digit  valid       WE
  5180.  
  5181.             other          invalid     E
  5182.  
  5183.  SE         decimal digit  valid       WE
  5184.  
  5185.             other          invalid     SE
  5186.  
  5187.  WE         decimal digit  valid       WE
  5188.  
  5189.             other          terminator  |
  5190. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  5191.  
  5192.  
  5193. ΓòÉΓòÉΓòÉ 7.3.2.2. FormatReal - Query real format ΓòÉΓòÉΓòÉ
  5194.  
  5195. PROCEDURE FormatReal (str: ARRAY OF CHAR): ConvResults;
  5196. PROCEDURE FormatReal (str: ARRAY OF CHAR): ConvResults;
  5197.  
  5198. Modules: RealConv, LongConv 
  5199.  
  5200. The function procedure FormatReal queries the format of str and returns: 
  5201.  
  5202.  strAllRight if str has a value representing a complete signed real number that 
  5203.            is in the range of the real number type corresponding to the module; 
  5204.  
  5205.  strOutOfRange if str has a value representing a complete signed real number 
  5206.            that is not in the range of the real number type corresponding to 
  5207.            the module; 
  5208.  
  5209.  strWrongFormat if str has a value with remaining characters that do not form a 
  5210.            complete signed real number; 
  5211.  
  5212.  strEmpty  if str has a value with no remaining characters; 
  5213.  
  5214.  FormatReal ignores any leading space characters in str. 
  5215.  
  5216.  
  5217. ΓòÉΓòÉΓòÉ 7.3.2.3. ValueReal - Query real value ΓòÉΓòÉΓòÉ
  5218.  
  5219. PROCEDURE ValueReal (str: ARRAY OF CHAR): REAL;
  5220. PROCEDURE ValueReal (str: ARRAY OF CHAR): LONGREAL;
  5221.  
  5222. Modules: RealConv, LongConv 
  5223.  
  5224. If str has a value representing a real number, the function procedure 
  5225. ValueReal(str) returns the REAL (or LONGREAL) value that corresponds most 
  5226. closely to that number. Otherwise, an exception is raised. 
  5227.  
  5228.  
  5229. ΓòÉΓòÉΓòÉ 7.3.2.4. LengthFloatReal - Query float length ΓòÉΓòÉΓòÉ
  5230.  
  5231. PROCEDURE LengthFloatReal (real: REAL;
  5232.                            sigFigs: CARDINAL): CARDINAL;
  5233. PROCEDURE LengthFloatReal (real: LONGREAL;
  5234.                            sigFigs: CARDINAL): CARDINAL;
  5235.  
  5236. Modules: RealConv, LongConv 
  5237.  
  5238. The function procedure LengthFloatReal returns the number of characters in the 
  5239. floating-point string representation of the value of real when using sigFigs 
  5240. significant figures. 
  5241.  
  5242. NOTE: 
  5243.  
  5244. This value corresponds to the capacity of an array str which is of the minimum 
  5245. capacity needed to avoid truncation of the result in the call 
  5246. RealStr.RealToFloat(real,sigFigs,str) (in the case of RealConv.LengthFloatReal) 
  5247. or the call LongStr.RealToFloat(real,sigFigs,str) (in the case of 
  5248. LongConv.LengthFloatReal). 
  5249.  
  5250.  
  5251. ΓòÉΓòÉΓòÉ 7.3.2.5. LengthEngReal - Query engineering length ΓòÉΓòÉΓòÉ
  5252.  
  5253. PROCEDURE LengthEngReal (real: REAL;
  5254.                          sigFigs: CARDINAL): CARDINAL;
  5255. PROCEDURE LengthEngReal (real: LONGREAL;
  5256.                          sigFigs: CARDINAL): CARDINAL;
  5257.  
  5258. Modules: RealConv, LongConv 
  5259.  
  5260. The function procedure LengthEngReal returns the number of characters in the 
  5261. floating-point engineering string representation of the value of real when 
  5262. using sigFigs significant figures. 
  5263.  
  5264. NOTE: 
  5265.  
  5266. This value corresponds to the capacity of an array str which is of the minimum 
  5267. capacity needed to avoid truncation of the result in the call 
  5268. RealStr.RealToEng(real,sigFigs,str) (in the case of RealConv.LengthEngReal) or 
  5269. the call LongStr.RealToEng(real,sigFigs,str) (in the case of 
  5270. LongConv.LengthEngReal). 
  5271.  
  5272.  
  5273. ΓòÉΓòÉΓòÉ 7.3.2.6. LengthFixedReal - Query fixed length ΓòÉΓòÉΓòÉ
  5274.  
  5275. PROCEDURE LengthFixedReal (real: REAL;
  5276.                            place: INTEGER): CARDINAL;
  5277. PROCEDURE LengthFixedReal (real: LONGREAL;
  5278.                            place: INTEGER): CARDINAL;
  5279.  
  5280. Modules: RealConv, LongConv 
  5281.  
  5282. The function procedure LengthFixedReal returns the number of characters in the 
  5283. fixed-point string representation of the value of real when rounded to the 
  5284. place relative to the decimal point given by the value of place. 
  5285.  
  5286. NOTE: 
  5287.  
  5288. This value corresponds to the capacity of an array str which is of the minimum 
  5289. capacity needed to avoid truncation of the result in the call 
  5290. RealStr.RealToFixed(real,place,str) (in the case of RealConv.LengthFixedReal) 
  5291. or the call LongStr.RealToFixed(real,place,str) (in the case of 
  5292. LongConv.LengthFixedReal). 
  5293.  
  5294.  
  5295. ΓòÉΓòÉΓòÉ 7.3.2.7. IsRConvException - Query exceptional state ΓòÉΓòÉΓòÉ
  5296.  
  5297. PROCEDURE IsRConvException (): BOOLEAN;
  5298. PROCEDURE IsRConvException (): BOOLEAN;
  5299.  
  5300. Modules: RealConv, LongConv 
  5301.  
  5302. If the calling coroutine is in the state of exceptional execution because of 
  5303. the raising of the RealConv exception, the function procedure 
  5304. RealConv.IsRConvException returns TRUE; otherwise it returns FALSE. 
  5305.  
  5306. If the calling coroutine is in the state of exceptional execution because of 
  5307. the raising of the LongConv exception, the function procedure 
  5308. LongConv.IsRConvException returns TRUE; otherwise it returns FALSE. 
  5309.  
  5310.  
  5311. ΓòÉΓòÉΓòÉ 8. Miscellaneous ΓòÉΓòÉΓòÉ
  5312.  
  5313.      Module CharClass 
  5314.      Modules LowReal and LowLong 
  5315.      Module Storage 
  5316.      Module SysClock 
  5317.  
  5318.  
  5319. ΓòÉΓòÉΓòÉ 8.1. Module CharClass ΓòÉΓòÉΓòÉ
  5320.  
  5321. The full set of values of the character type (the elementary type denoted by 
  5322. the pervasive identifier CHAR) is implementation-defined. The module CharClass 
  5323. allows a program to determine the classification of a given value of the 
  5324. character type of an implementation in a way that does not rely on there being 
  5325. a known literal representation of all members of the character set. 
  5326.  
  5327. The module CharClass provides predicates to test if a given value of the 
  5328. character type in an implementation is classified as a numeric, a letter, an 
  5329. upper-case letter, a lower-case letter, a value representing a control 
  5330. function, or as white space. 
  5331.  
  5332.      IsNumeric - Test for numeric character 
  5333.      IsLetter - Test for letter 
  5334.      IsUpper - Test for upper case letter 
  5335.      IsLower - Test for lower case letter 
  5336.      IsControl - Test for control character 
  5337.      IsWhiteSpace - Test for white space character 
  5338.  
  5339.  
  5340. ΓòÉΓòÉΓòÉ 8.1.1. IsNumeric - Test for numeric character ΓòÉΓòÉΓòÉ
  5341.  
  5342. PROCEDURE IsNumeric (ch: CHAR): BOOLEAN;
  5343.  
  5344. Module CharClass 
  5345.  
  5346. The function procedure IsNumeric returns TRUE if ch is a member of an 
  5347. implementation-defined set of numeric characters that should include the 
  5348. decimal digits, and FALSE otherwise. 
  5349.  
  5350.  
  5351. ΓòÉΓòÉΓòÉ 8.1.2. IsLetter - Test for letter ΓòÉΓòÉΓòÉ
  5352.  
  5353. PROCEDURE IsLetter (ch: CHAR): BOOLEAN;
  5354.  
  5355. Module CharClass 
  5356.  
  5357. The function procedure IsLetter returns TRUE if ch is a member of an 
  5358. implementation-defined set of letters that should include the required letters, 
  5359. and FALSE otherwise. 
  5360.  
  5361.  
  5362. ΓòÉΓòÉΓòÉ 8.1.3. IsUpper - Test for upper case letter ΓòÉΓòÉΓòÉ
  5363.  
  5364. PROCEDURE IsUpper (ch: CHAR): BOOLEAN;
  5365.  
  5366. Module CharClass 
  5367.  
  5368. The function procedure IsUpper returns TRUE if ch is a member of an 
  5369. implementation-defined set of upper case letters that should include the 
  5370. required upper case letters, and FALSE otherwise. 
  5371.  
  5372.  
  5373. ΓòÉΓòÉΓòÉ 8.1.4. IsLower - Test for lower case letter ΓòÉΓòÉΓòÉ
  5374.  
  5375. PROCEDURE IsLower (ch: CHAR): BOOLEAN;
  5376.  
  5377. Module CharClass 
  5378.  
  5379. The function procedure IsLower returns TRUE if ch is a member of an 
  5380. implementation-defined set of lower case letters that should include the 
  5381. required lower case letters, and FALSE otherwise. 
  5382.  
  5383.  
  5384. ΓòÉΓòÉΓòÉ 8.1.5. IsControl - Test for control character ΓòÉΓòÉΓòÉ
  5385.  
  5386. PROCEDURE IsControl (ch: CHAR): BOOLEAN;
  5387.  
  5388. Module CharClass 
  5389.  
  5390. The function procedure IsControl returns TRUE if ch is a member of an 
  5391. implementation-defined set of characters that represent control functions, and 
  5392. FALSE otherwise. 
  5393.  
  5394.  
  5395. ΓòÉΓòÉΓòÉ 8.1.6. IsWhiteSpace - Test for white space character ΓòÉΓòÉΓòÉ
  5396.  
  5397. PROCEDURE IsWhiteSpace (ch: CHAR): BOOLEAN;
  5398.  
  5399. Module CharClass 
  5400.  
  5401. The function procedure IsWhiteSpace returns TRUE if ch is either a space 
  5402. character or a member of an implementation-defined set of characters that 
  5403. represent format effectors, and FALSE otherwise. 
  5404.  
  5405.  
  5406. ΓòÉΓòÉΓòÉ 8.2. Modules LowReal and LowLong ΓòÉΓòÉΓòÉ
  5407.  
  5408. Two modules are provided to give access to the underlying properties of the 
  5409. types REAL and LONGREAL. The two modules share common concepts, functions and 
  5410. values, and hence both modules are considered together. 
  5411.  
  5412. The module LowReal gives access to the underlying properties of the type REAL, 
  5413. while LowLong gives access to the same properties for the type LONGREAL. 
  5414.  
  5415. For implementations that conform to ISO/IEC 10967-1:199x Information technology 
  5416. - Language independent arithmetic - Part1: Integer and floating point 
  5417. arithmetic, a more precise specification is given in that International 
  5418. Standard. 
  5419.  
  5420. If the implementation of the corresponding real number type conforms to ISO/IEC 
  5421. 10967-1:199x (LIA-1), procedure functions of a similar name correspond to the 
  5422. operations required by that International Standard. 
  5423.  
  5424.      Constants and Types - 
  5425.      exponent - Exponent value 
  5426.      fraction - Significand part 
  5427.      sign - Signum 
  5428.      succ - Next greater value 
  5429.      ulp - Unit in the last place 
  5430.      pred - Previous less value 
  5431.      intpart - Integral part 
  5432.      fractpart - Fractional part 
  5433.      scale - Scale 
  5434.      trunc - Truncate 
  5435.      round - Round 
  5436.      synthesize - Construct value 
  5437.      setMode - Set status flags 
  5438.      currentMode - Current status flags 
  5439.      IsLowException - Query exceptional state 
  5440.  
  5441.  
  5442. ΓòÉΓòÉΓòÉ 8.2.1. Constants and Types - ΓòÉΓòÉΓòÉ
  5443.  
  5444. CONST
  5445.   radix = <implementation-defined whole number value>;
  5446.   places = <implementation-defined whole number value>;
  5447.   expoMin = <implementation-defined whole number value>;
  5448.   expoMax = <implementation-defined whole number value>;
  5449.   large = <implementation-defined real number value>;
  5450.   small = <implementation-defined real number value>;
  5451.   IEC559 = <implementation-defined BOOLEAN value>;
  5452.   LIA1 = <implementation-defined BOOLEAN value>;
  5453.   rounds = <implementation-defined BOOLEAN value>;
  5454.   gUnderflow = <implementation-defined BOOLEAN value>;
  5455.   exception = <implementation-defined BOOLEAN value>;
  5456.   extend = <implementation-defined BOOLEAN value>;
  5457.   nModes = <implementation-defined whole number value>;
  5458. TYPE
  5459.   Modes = PACKEDSET OF [0 .. nModes-1];
  5460.  
  5461. Modules: LowReal, LowLong 
  5462.  
  5463. The values denoted by the constant identifiers exported from LowReal and 
  5464. LowLong are the implementation-defined values specified below. 
  5465.  
  5466. If an implementation provides facilities for dynamically changing the 
  5467. properties of the real number types, the constant values refer to the default 
  5468. properties. 
  5469.  
  5470. The value of places, and the other facilities in these modules, refer only to 
  5471. the representation used to store values. 
  5472.  
  5473. NOTE: Some implementations may choose to compute expressions to greater 
  5474. precision than that used to store values. 
  5475.  
  5476. If the implementation of the corresponding real number type conforms to ISO/IEC 
  5477. 10967-1:199x (LIA-1), the following correspondences hold: 
  5478.  
  5479. NOTE: The value of the parameter fmax, required by ISO/IEC 10967-1:199x, is 
  5480. given by the predefined function MAX when applied to the corresponding real 
  5481. number type. 
  5482.  
  5483.  radix     The whole number value of the radix used to represent the 
  5484.            corresponding real number values. 
  5485.  
  5486.  places    The whole number value of the number of radix places used to store 
  5487.            values of the corresponding real number type. 
  5488.  
  5489.  expoMin   The whole number value of the exponent minimum. 
  5490.  
  5491.  expoMax   The whole number value of the exponent maximum. 
  5492.  
  5493.            NOTE: An implementation may choose values such that expoMin = 
  5494.            expoMax (which will presumably be the case for a fixed point 
  5495.            representation). 
  5496.  
  5497.  large     The largest value of the corresponding real number type. 
  5498.  
  5499.            NOTE: On some implementations this may be a machine representation 
  5500.            of infinity. 
  5501.  
  5502.  small     The smallest positive value of the corresponding real number type, 
  5503.            represented to maximal precision. 
  5504.  
  5505.            NOTE: If an implementation has stored values strictly between 0.0 
  5506.            and small, then presumably the implementation supports gradual 
  5507.            underflow. 
  5508.  
  5509.  IEC559    A Boolean value that is true if and only if the implementation of 
  5510.            the corresponding real number type conforms to IEC 559:1989 (IEEE 
  5511.            754:1987) in all regards. 
  5512.  
  5513.            NOTES: 
  5514.  
  5515.                If IEC559 is true, the value of radix is 2. 
  5516.  
  5517.                If LowReal.IEC559 is true, the 32-bit format of IEC 559:1989 is 
  5518.                 used for the type REAL. 
  5519.  
  5520.                If LowLong.IEC559 is true, the 64-bit format of IEC 559:1989 is 
  5521.                 used for the type LONGREAL. 
  5522.  
  5523.  LIA1      A Boolean value that is true if and only if the implementation of 
  5524.            the corresponding real number type conforms to ISO/IEC 10967-1:199x 
  5525.            (LIA-1) in all regards: parameters, arithmetic, exceptions, and 
  5526.            notification. 
  5527.  
  5528.            NOTE: For implementations not conforming to ISO/IEC 10967-1:199x, 
  5529.            the corresponding properties are implementation-defined | see 
  5530.            6.8.2.2. 
  5531.  
  5532.  rounds    A Boolean value that is true if and only if each operation produces 
  5533.            a result that is one of the values of the corresponding real number 
  5534.            type nearest to the mathematical result. 
  5535.  
  5536.            NOTE: If rounds is true, and the mathematical result lies mid-way 
  5537.            between two values of the corresponding real number type, then the 
  5538.            selection from the two possible values is implementation-dependent. 
  5539.  
  5540.  gUnderflow A Boolean value that is true if and only if there are values of the 
  5541.            corresponding real number type between 0.0 and small. 
  5542.  
  5543.  exception A Boolean value that is true if and only if every operation that 
  5544.            attempts to produce a real value out of range raises an exception. 
  5545.  
  5546.  extend    A Boolean value that is true if and only if expressions of the 
  5547.            corresponding real number type are computed to higher precision than 
  5548.            the stored values. 
  5549.  
  5550.            NOTE: If extend is true, then values greater than large can be 
  5551.            computed in expressions, but cannot be stored in variables. 
  5552.  
  5553.  nModes    The whole number value giving the number of bit positions needed for 
  5554.            the status flags for mode control. 
  5555.  
  5556.  
  5557. ΓòÉΓòÉΓòÉ 8.2.2. exponent - Exponent value ΓòÉΓòÉΓòÉ
  5558.  
  5559. PROCEDURE exponent (x: REAL): INTEGER;
  5560. PROCEDURE exponent (x: LONGREAL): INTEGER;
  5561.  
  5562. Modules: LowReal, LowLong 
  5563.  
  5564. The function procedure exponent returns the exponent value of x that lies 
  5565. between expoMin and expoMax. An exception occurs and may be raised if x is 
  5566. equal to 0.0. 
  5567.  
  5568.  
  5569. ΓòÉΓòÉΓòÉ 8.2.3. fraction - Significand part ΓòÉΓòÉΓòÉ
  5570.  
  5571. PROCEDURE fraction (x: REAL): REAL;
  5572. PROCEDURE fraction (x: LONGREAL): LONGREAL;
  5573.  
  5574. Modules: LowReal, LowLong 
  5575.  
  5576. The function procedure fraction returns the significand (or significant) part 
  5577. of x. Hence the following relationship shall hold: 
  5578.  
  5579. x = scale(fraction(x), exponent(x)) 
  5580.  
  5581.  
  5582. ΓòÉΓòÉΓòÉ 8.2.4. sign - Signum ΓòÉΓòÉΓòÉ
  5583.  
  5584. PROCEDURE sign (x: REAL): REAL;
  5585. PROCEDURE sign (x: LONGREAL): LONGREAL;
  5586.  
  5587. Modules: LowReal, LowLong 
  5588.  
  5589. The function procedure sign returns 1.0 if x is greater than 0.0, -1.0 if x is 
  5590. less than 0.0, or either 1.0 or -1.0 if x is equal to 0.0. 
  5591.  
  5592. NOTE: The uncertainty about the handling of 0.0 is to allow for systems that 
  5593. distinguish between +0.0 and -0.0 (such as IEEE 754 systems). 
  5594.  
  5595.  
  5596. ΓòÉΓòÉΓòÉ 8.2.5. succ - Next greater value ΓòÉΓòÉΓòÉ
  5597.  
  5598. PROCEDURE succ (x: REAL): REAL;
  5599. PROCEDURE succ (x: LONGREAL): LONGREAL;
  5600.  
  5601. Modules: LowReal, LowLong 
  5602.  
  5603. The function procedure succ returns the next value of the corresponding real 
  5604. number type greater than x, if such a value exists; otherwise an exception 
  5605. occurs and may be raised. 
  5606.  
  5607.  
  5608. ΓòÉΓòÉΓòÉ 8.2.6. ulp - Unit in the last place ΓòÉΓòÉΓòÉ
  5609.  
  5610. PROCEDURE ulp (x: REAL): REAL;
  5611. PROCEDURE ulp (x: LONGREAL): LONGREAL;
  5612.  
  5613. Modules: LowReal, LowLong 
  5614.  
  5615. The function procedure ulp returns the value of the corresponding real number 
  5616. type equal to a unit in the last place of x, if such a value exists; otherwise 
  5617. an exception occurs and may be raised. 
  5618.  
  5619. NOTE: Thus, when the value exists, either ulp(x) = succ(x)-x or ulp(x) = 
  5620. x-pred(x) or both is true. 
  5621.  
  5622.  
  5623. ΓòÉΓòÉΓòÉ 8.2.7. pred - Previous less value ΓòÉΓòÉΓòÉ
  5624.  
  5625. PROCEDURE pred (x: REAL): REAL;
  5626. PROCEDURE pred (x: LONGREAL): LONGREAL;
  5627.  
  5628. Modules: LowReal, LowLong 
  5629.  
  5630. The function procedure pred returns the next value of the corresponding real 
  5631. number type less than x, if such a value exists; otherwise an exception occurs 
  5632. and may be raised. 
  5633.  
  5634.  
  5635. ΓòÉΓòÉΓòÉ 8.2.8. intpart - Integral part ΓòÉΓòÉΓòÉ
  5636.  
  5637. PROCEDURE intpart (x: REAL): REAL;
  5638. PROCEDURE intpart (x: LONGREAL): LONGREAL;
  5639.  
  5640. Modules: LowReal, LowLong 
  5641.  
  5642. The function procedure intpart returns the integral part of x. For negative 
  5643. values, this shall be -intpart(abs(x)). 
  5644.  
  5645.  
  5646. ΓòÉΓòÉΓòÉ 8.2.9. fractpart - Fractional part ΓòÉΓòÉΓòÉ
  5647.  
  5648. PROCEDURE fractpart (x: REAL): REAL;
  5649. PROCEDURE fractpart (x: LONGREAL): LONGREAL;
  5650.  
  5651. Modules: LowReal, LowLong 
  5652.  
  5653. The function procedure fractpart returns the fractional part of x. This 
  5654. satisfies the relationship fractpart(x)+intpart(x)=x. 
  5655.  
  5656.  
  5657. ΓòÉΓòÉΓòÉ 8.2.10. scale - Scale ΓòÉΓòÉΓòÉ
  5658.  
  5659. PROCEDURE scale (x: REAL; n: INTEGER): REAL;
  5660. PROCEDURE scale (x: LONGREAL; n: INTEGER): LONGREAL;
  5661.  
  5662. Modules: LowReal, LowLong 
  5663.  
  5664. The function procedure scale returns the value x * radix ** n if such a value 
  5665. exists; otherwise an exception occurs and may be raised. 
  5666.  
  5667.  
  5668. ΓòÉΓòÉΓòÉ 8.2.11. trunc - Truncate ΓòÉΓòÉΓòÉ
  5669.  
  5670. PROCEDURE trunc (x: REAL; n: INTEGER): REAL;
  5671. PROCEDURE trunc (x: LONGREAL; n: INTEGER): LONGREAL;
  5672.  
  5673. Modules: LowReal, LowLong 
  5674.  
  5675. The function procedure trunc returns the value of the most significant n places 
  5676. of x. An exception occurs and may be raised if n is less than or equal to zero. 
  5677.  
  5678.  
  5679. ΓòÉΓòÉΓòÉ 8.2.12. round - Round ΓòÉΓòÉΓòÉ
  5680.  
  5681. PROCEDURE round (x: REAL; n: INTEGER): REAL;
  5682. PROCEDURE round (x: LONGREAL; n: INTEGER): LONGREAL;
  5683.  
  5684. Modules: LowReal, LowLong 
  5685.  
  5686. The function procedure round returns the value of x rounded to the most 
  5687. significant n places. An exception occurs and may be raised if such a value 
  5688. does not exist, or if n is less than or equal to zero. 
  5689.  
  5690.  
  5691. ΓòÉΓòÉΓòÉ 8.2.13. synthesize - Construct value ΓòÉΓòÉΓòÉ
  5692.  
  5693. PROCEDURE synthesize (expart: INTEGER; frapart: REAL): REAL;
  5694. PROCEDURE synthesize (expart: INTEGER; frapart: LONGREAL): LONGREAL;
  5695.  
  5696. Modules: LowReal, LowLong 
  5697.  
  5698. The function procedure synthesize returns a value of the corresponding real 
  5699. number type constructed from the values of expart and frapart. This value shall 
  5700. satisfy the relationship: 
  5701. synthesize(exponent(x),fraction(x))=x 
  5702.  
  5703.  
  5704. ΓòÉΓòÉΓòÉ 8.2.14. setMode - Set status flags ΓòÉΓòÉΓòÉ
  5705.  
  5706. PROCEDURE setMode (m: Modes);
  5707. PROCEDURE setMode (m: Modes);
  5708.  
  5709. Modules: LowReal, LowLong 
  5710.  
  5711. The procudure setMode sets status flags from the value of m, appropriate to the 
  5712. underlying implementation of the corresponding real number type. 
  5713.  
  5714. NOTES: 
  5715.  
  5716.      Many implementations of floating point provide options for setting status 
  5717.       flags within the system which control details of the handling of the 
  5718.       type. Although two procedures are provided, one for each real number 
  5719.       type, the effect may be the same. Typical effects that can be obtained by 
  5720.       this means are: 
  5721.  
  5722.         -  Ensuring that overflow will raise an exception; 
  5723.  
  5724.         -  Allowing underflow to raise an exception; 
  5725.  
  5726.         -  Controlling the rounding; 
  5727.  
  5728.         -  Allowing special values to be produced (e.g. NaNs in implementations 
  5729.            conforming to IEC 559:1989 (IEEE 754:1987)); 
  5730.  
  5731.         -  Ensuring that special value access will raise an exception; 
  5732.  
  5733.       Since these effects are so varied, the values of type Modes that may be 
  5734.       used are not specified by this International Standard. 
  5735.  
  5736.      The effect of setMode on operations on values of the corresponding real 
  5737.       number type in coroutines other than the calling coroutine is not 
  5738.       defined. Implementations are not required to preserve the status flags 
  5739.       (if any) with the coroutine state. 
  5740.  
  5741.  
  5742. ΓòÉΓòÉΓòÉ 8.2.15. currentMode - Current status flags ΓòÉΓòÉΓòÉ
  5743.  
  5744. PROCEDURE currentMode (): Modes;
  5745. PROCEDURE currentMode (): Modes;
  5746.  
  5747. Modules: LowReal, LowLong 
  5748.  
  5749. The function procedure currentMode returns the current status flags (in the 
  5750. form set by setMode), or the default status flags (if setMode is not used). 
  5751.  
  5752. NOTE: The returned value is not necessarily the value set by setMode, since a 
  5753. call of setMode might attempt to set flags that cannot be set by the program. 
  5754.  
  5755.  
  5756. ΓòÉΓòÉΓòÉ 8.2.16. IsLowException - Query exceptional state ΓòÉΓòÉΓòÉ
  5757.  
  5758. PROCEDURE IsLowException (): BOOLEAN;
  5759. PROCEDURE IsLowException (): BOOLEAN;
  5760.  
  5761. Modules: LowReal, LowLong 
  5762.  
  5763. If the calling coroutine is in the state of exceptional execution because of 
  5764. the raising of the LowReal exception, the function procedure 
  5765. LowReal.IsLowException returns TRUE; otherwise is returns FALSE. 
  5766.  
  5767. If the calling coroutine is in the state of exceptional execution because of 
  5768. the raising of the LowLong exception, the function procedure 
  5769. LowLong.IsLowException returns TRUE; otherwise is returns FALSE. 
  5770.  
  5771.  
  5772. ΓòÉΓòÉΓòÉ 8.3. Module Storage ΓòÉΓòÉΓòÉ
  5773.  
  5774. The module Storage provides facilities for dynamically allocating and 
  5775. deallocating storage for variables that are not declared in variable 
  5776. declarations. Variables with storage allocated in this way are designated by 
  5777. dereferenced variable designators. The facilities are often invoked by using 
  5778. the predefined procedures NEW and DISPOSE. The facilities can also be used to 
  5779. allocate storage to be used as coroutine workspace. 
  5780.  
  5781. The semantics are described in terms of allocating storage for a variable since 
  5782. the allocator must take account of any address alignment requirements for the 
  5783. storage of variables of the given size. 
  5784.  
  5785. CLARIFICATIONS 
  5786.  
  5787.      Programming in Modula-2 adopts two approaches to handling situations 
  5788.       where it is not possible to allocate sufficient storage; the procedure 
  5789.       Allocate of Chapter 25 assigns NIL to the first parameter, whereas the 
  5790.       procedure ALLOCATE of Appendix 2 causes the program to terminate. The 
  5791.       International Standard requires the procedure ALLOCATE to assign the 
  5792.       value NIL to its first parameter in this situation. 
  5793.  
  5794.      Although the first parameter of the procedure DEALLOCATE given in 
  5795.       Appendix 2 of Programming in Modula-2 is a variable parameter, it is not 
  5796.       stated whether DEALLOCATE assigns a value to its parameter. The 
  5797.       International Standard requires the procedure DEALLOCATE to assign the 
  5798.       value NIL to its parameter. 
  5799.  
  5800.      StorageExceptions - Storage exceptions identities 
  5801.      ALLOCATE - Allocate storage 
  5802.      DEALLOCATE - Deallocate storage 
  5803.      IsStorageException - Query exceptional state 
  5804.      StorageException - Query exception id 
  5805.  
  5806.  
  5807. ΓòÉΓòÉΓòÉ 8.3.1. StorageExceptions - Storage exceptions identities ΓòÉΓòÉΓòÉ
  5808.  
  5809. TYPE
  5810.   StorageExceptions = (
  5811.     nilDeallocation,
  5812.       (* first argument to DEALLOCATE is NIL *)
  5813.     pointerToUnallocatedStorage,
  5814.       (* storage to deallocate not allocated by ALLOCATE *)
  5815.     wrongStorageToUnallocate
  5816.       (* amount to deallocate is not amount allocated *)
  5817. );
  5818.  
  5819. Module Storage 
  5820.  
  5821. The exceptions raised by Storage are identified by the values of the 
  5822. enumeration type StorageExceptions. 
  5823.  
  5824. The detection of the exception wrongStorageToUnallocate is 
  5825. implementation-defined. 
  5826.  
  5827.  
  5828. ΓòÉΓòÉΓòÉ 8.3.2. ALLOCATE - Allocate storage ΓòÉΓòÉΓòÉ
  5829.  
  5830. PROCEDURE ALLOCATE (VAR addr: SYSTEM.ADDRESS;
  5831.                     amount: CARDINAL);
  5832.  
  5833. Module Storage 
  5834.  
  5835. The procedure ALLOCATE allocates storage for a variable of size amount, and 
  5836. assigns the address of this variable to addr. The allocated locations will not 
  5837. be in use for the storage of any other variable. If it is not possible to 
  5838. allocate this storage, the value NIL is assigned to addr. 
  5839.  
  5840. NOTES: 
  5841.  
  5842.    1. If an address passed back by a call of ALLOCATE is assigned to a pointer 
  5843.       variable vp that is to be dereferenced to designate a variable of type T, 
  5844.       the value for the second parameter to ALLOCATE may be obtained from 
  5845.       evaluation of the expression SIZE(T). An equivalent effect may be 
  5846.       obtained as NEW(vp). 
  5847.  
  5848.    2. If an address passed back by a call of ALLOCATE is to be given directly 
  5849.       as the workspace address in a call of COROUTINES.NEWCOROUTINE, the value 
  5850.       for the second parameter to ALLOCATE is the size of workspace required. 
  5851.  
  5852.  
  5853. ΓòÉΓòÉΓòÉ 8.3.3. DEALLOCATE - Deallocate storage ΓòÉΓòÉΓòÉ
  5854.  
  5855. PROCEDURE DEALLOCATE (VAR addr: SYSTEM.ADDRESS;
  5856.                       amount: CARDINAL);
  5857.  
  5858. Module Storage 
  5859.  
  5860. The procedure DEALLOCATE deallocates amount locations for the storage of the 
  5861. variable addressed by addr and assigns the value NIL to addr. 
  5862.  
  5863. The exception nilDeallocation is raised if the given value of addr is the nil 
  5864. value. The exception pointerToUnallocatedStorage is raised if the given value 
  5865. of addr is not the address of a variable whose storage has been allocated by 
  5866. ALLOCATE. The exception wrongStorageToUnallocate occurs and may be raised if 
  5867. amount is not equal to the number of locations allocated for the storage of the 
  5868. variable addressed by addr. 
  5869.  
  5870. NOTES: 
  5871.  
  5872.    1. If an address passed to a call of DEALLOCATE is the value of a pointer 
  5873.       variable vp that is dereferenced to designate a variable of type T, the 
  5874.       value for the second parameter to DEALLOCATE may be obtained from 
  5875.       evaluation of the expression SIZE(T). An equivalent effect may be 
  5876.       obtained as DISPOSE(vp). 
  5877.  
  5878.    2. The variable whose storage is deallocated no longer exists and hence an 
  5879.       exception occurs, which may be raised, if there is a subsequent attempt 
  5880.       to access the variable through a dereferenced designator. 
  5881.  
  5882.    3. This International Standard gives no meaning for a program that 
  5883.       deallocates dynamic storage given as workspace in a call of 
  5884.       COROUTINES.NEWCOROUTINE since the use made of coroutine workspace is 
  5885.       implementation-dependent. 
  5886.  
  5887.    4. It need not be the case that storage locations deallocated by a call of 
  5888.       DEALLOCATE are available for re-use by a subsequent call of ALLOCATE. 
  5889.  
  5890.  
  5891. ΓòÉΓòÉΓòÉ 8.3.4. IsStorageException - Query exceptional state ΓòÉΓòÉΓòÉ
  5892.  
  5893. PROCEDURE IsStorageException (): BOOLEAN;
  5894.  
  5895. Module Storage 
  5896.  
  5897. If the calling coroutine is in the state of exceptional execution because of 
  5898. the raising of a Storage exception, the function procedure IsStorageException 
  5899. returns TRUE; otherwise it returns FALSE. 
  5900.  
  5901.  
  5902. ΓòÉΓòÉΓòÉ 8.3.5. StorageException - Query exception id ΓòÉΓòÉΓòÉ
  5903.  
  5904. PROCEDURE StorageException (): StorageExceptions;
  5905.  
  5906. Module Storage 
  5907.  
  5908. If the calling coroutine is in the state of exceptional execution because of 
  5909. the raising of a Storage exception, the function procedure StorageException 
  5910. returns the value that identifies the raised exception; otherwise the language 
  5911. exception exException is raised. 
  5912.  
  5913.  
  5914. ΓòÉΓòÉΓòÉ 8.4. Module SysClock ΓòÉΓòÉΓòÉ
  5915.  
  5916. The module SysClock provides facilities for accessing a system clock that 
  5917. records the date and time of day. 
  5918.  
  5919. NOTES: 
  5920.  
  5921.      No provision is made for leap seconds. 
  5922.  
  5923.      `UTC' is `Universal Coordinated Time'. This is the correct international 
  5924.       designation for what was once called `GMT' (Greenwich Mean Time). 
  5925.  
  5926.      The field summerTimeFlag is present for information only. UTC can always 
  5927.       be obtained by subtracting the UTCDiff value from the time data, 
  5928.       regardless of the value of the summerTimeFlag. However, its presence does 
  5929.       allow a program to know whether or not the date and time data represents 
  5930.       standard time for that location, or `summer time'. A program could 
  5931.       therefore be written to change the system clock to summer time 
  5932.       automatically on a certain date, provided it had not already been 
  5933.       changed. 
  5934.  
  5935.      The Constants and Types of SysClock 
  5936.      CanGetClock - Query system clock read permission 
  5937.      CanSetClock - Query system clock write permission 
  5938.      IsValidDateTime - Verify date and time 
  5939.      GetClock - Determine current date and time 
  5940.      SetClock - Set current date and time 
  5941.  
  5942.  
  5943. ΓòÉΓòÉΓòÉ 8.4.1. The Constants and Types of SysClock ΓòÉΓòÉΓòÉ
  5944.  
  5945. CONST
  5946.   maxSecondParts = <implementation-defined integral value>;
  5947.  
  5948. TYPE
  5949.   Month = [1 .. 12];
  5950.   Day = [1 .. 31];
  5951.   Hour = [0 .. 23];
  5952.   Min = [0 .. 59];
  5953.   Sec = [0 .. 59];
  5954.   Fraction = [0 .. maxSecondParts];
  5955.   UTCDiff = [-780 .. 720];
  5956.   DateTime =
  5957.     RECORD
  5958.       year:   CARDINAL;
  5959.       month:  Month;
  5960.       day:    Day;
  5961.       hour:   Hour;
  5962.       minute: Min;
  5963.       second: Sec;
  5964.       fractions: Fraction; (* parts of a second *)
  5965.       zone:   UTCDiff;
  5966.         (* Time zone differential factor which is the number
  5967.            of minutes to add to local time to obtain UTC. *)
  5968.       summerTimeFlag: BOOLEAN;
  5969.         (* Interpretation of flag depends on local usage. *)
  5970.     END;
  5971.  
  5972.  
  5973. ΓòÉΓòÉΓòÉ 8.4.2. CanGetClock - Query system clock read permission ΓòÉΓòÉΓòÉ
  5974.  
  5975. PROCEDURE CanGetClock (): BOOLEAN;
  5976.  
  5977. Module SysClock 
  5978.  
  5979. The function procedure CanGetClock returns an implementation-defined BOOLEAN 
  5980. value. If the value TRUE is returned, there is a system clock which the program 
  5981. is permitted to read. 
  5982.  
  5983.  
  5984. ΓòÉΓòÉΓòÉ 8.4.3. CanSetClock - Query system clock write permission ΓòÉΓòÉΓòÉ
  5985.  
  5986. PROCEDURE CanSetClock (): BOOLEAN;
  5987.  
  5988. Module SysClock 
  5989.  
  5990. The function procedure CanSetClock() returns an implementation-defined BOOLEAN 
  5991. value. If the value TRUE is returned, there is a system clock which the program 
  5992. is permitted to set. 
  5993.  
  5994.  
  5995. ΓòÉΓòÉΓòÉ 8.4.4. IsValidDateTime - Verify date and time ΓòÉΓòÉΓòÉ
  5996.  
  5997. PROCEDURE IsValidDateTime (userData: DateTime): BOOLEAN;
  5998.  
  5999. Module SysClock 
  6000.  
  6001. The function procedure IsValidDateTime returns TRUE if the value of userData 
  6002. represents a valid date and time, and is FALSE otherwise. 
  6003.  
  6004. NOTE: 
  6005.  
  6006. Only the date components of userData need to be validated since all 
  6007. combinations of values of the time components are known to be valid. 
  6008.  
  6009.  
  6010. ΓòÉΓòÉΓòÉ 8.4.5. GetClock - Determine current date and time ΓòÉΓòÉΓòÉ
  6011.  
  6012. PROCEDURE GetClock (VAR userData: DateTime);
  6013.  
  6014. Module SysClock 
  6015.  
  6016. The function procedure GetClock assigns values for each field of the variable 
  6017. userData for which information is available. Each of the remaining fields of 
  6018. userData are set to zero, where this is a valid value, and otherwise are set to 
  6019. the lower bound of the range of allowed values. 
  6020.  
  6021.  
  6022. ΓòÉΓòÉΓòÉ 8.4.6. SetClock - Set current date and time ΓòÉΓòÉΓòÉ
  6023.  
  6024. PROCEDURE SetClock (userData: DateTime);
  6025.  
  6026. Module SysClock 
  6027.  
  6028. The function procedure SetClock sets the system clock to the date and time 
  6029. specified by userData, provided that the program may set the system clock, and 
  6030. that the value of userData represents a valid date and time. If the program 
  6031. cannot set the system clock, a call of SetClock have no effect. 
  6032.  
  6033. NOTE: 
  6034.  
  6035. The effect of a call of SetClock is implementation-dependent if it is permitted 
  6036. to set the system clock, but an invalid date and time is given.